Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
foreach (DataRow row in dt.Rows)
                    {
                        lstData.Add(new Tablelist() { FileName = csv.Replace(".csv", "").Replace(".CSV", ""), process = row["process"] + "", Event = row["Event"] + "", status = row["status"] + "" });

                    }
                }
                var RowNames = lstData.Select(k => k.FileName).Distinct();

                foreach (string rowName in RowNames)
                   
                    dtoutput.Rows.Add(rowName, typeof(string));

I'm getting this error "Input array is longer than the number of columns in this table" is it because I didn't add a column for this row, but when I add I still get this error .. can anyone guide me?..
Posted
Updated 7-Jan-14 16:46pm
v2
Comments
Gitanjali Singh 7-Jan-14 22:47pm    
where you have declared dtoutput?
acing wei 7-Jan-14 23:10pm    
have on top of var rownames..
JoCodes 7-Jan-14 23:54pm    
You need to add the column first then the add the rows

1 solution

Quote:
"Input array is longer than the number of columns in this table"
Refer - [MSDN] Adding Columns to a DataTable[^]
You need to add the Columns for DataTable before adding Rows to that.
C#
dt.Columns.Add("Column1", typeof (string));
dt.Columns.Add("Column2", typeof (string));
dt.Columns.Add("Column3", typeof(string));
dt.Columns.Add("Column4", typeof(string));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900