C# .NET - Create dataRow for a specific datatable

Asked By Niron Kag on 26-Apr-06 08:22 AM
I create a dataTable with specific Columns and I want to create match dataRow (with the same columns).
how can I do that ?
Thank U !!!

DataRow

Asked By Ramya T on 26-Apr-06 08:41 AM
check this example at the bottom of the page to add rows for the columns you created:
http://authors.aspalliance.com/aspxtreme/sys/data/DataColumnClass.aspx

Basic pattern

Asked By Peter Bromberg on 26-Apr-06 10:58 AM
DataRow row = MyDataTable.NewRow();
row.ItemArray=new object[] {col1Value, col2Value};
MyDataTable.Rows.Add(row);

sample

Vijay R replied to Niron Kag on 29-Apr-09 07:45 AM
DataTable dt = new DataTable();
DataRow myNewRow;
myNewRow = dt.NewRow();
myNewRow["customerId"] = 1;
myNewRow["username"] = "vijay" ;
dt.Rows.Add(myNewRow);
Mike replied to Peter Bromberg on 15-Apr-10 02:26 PM
Thanks a million....

Was able to complete the finishing touches on my app by using this technique!

Amr replied to Peter Bromberg on 16-Dec-10 08:59 AM
Nice but You Must Define The DataTable's Columns before adding.
 
e.g ... If you planning to add two columns :

MyDataTable.Columns.Add("Col No.1");

MyDataTable.Columns.Add("Col No.2");

//and Then
row.ItemArray=new object[] {col1Value, col2Value};
MyDataTable.Rows.Add(row);

Regards.

Peter Bromberg replied to Amr on 16-Dec-10 09:12 AM
No, because his columns were already defined. He just wants to add a new row.