views:

2534

answers:

2

Hi..

I want to convert an datarow array into datatable.. Wat is the simple way to do this?

Thanks in advance!!

+1  A: 
DataTable dt = new DataTable(); 

DataRow[] dr = (DataTable)dsData.Tables[0].Select("Some Criteria");

dt.Rows.Add(dr);
Mitch Wheat
I already tried like that.. Error occurs something like "Input array is longer than the number of columns in this table."
Nila
AS Jay pointed out, Make sure your dataTable has the same schema as the DataRows in your DataRow array
Mitch Wheat
Yes.. I tried. I used Datatable1=datatable2.Clone(); Now it is working... Thank you :-)
Nila
I tried this with a row array and it didn't work. For each row in the row array, I created a new row, copied the ItemArray property from the original row and then the add worked.
Steve
+2  A: 

Why not iterate through your DataRow array and add (using DataRow.ImportRow, if necessary, to get a copy of the DataRow), something like:

foreach (DataRow row in rowArray) {
   dataTable.ImportRow(row);
}

Make sure your dataTable has the same schema as the DataRows in your DataRow array.

Jay Riggs