I\'m trying to make a DataTable and then add a couple rows to it. Here\'s my code:
using System;
using System.Collections.Generic;
using System.Linq;
using
Try this code:
dt.Rows.Add(dr)
You first need to add the row:
dt.Rows.Add(dr);
Then you must call below method to commit it:
dt.AcceptChanges();
If the row is detached (as it is when it is first created) ImportRows fails silently (no exception) - to be able to import rows you have to Add it into the table. Afterwards you can import it into other tables.
Its May Help you
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
//
// Here we add five DataRows.
//
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);