Why doesn't ImportRow() work?

  • Thread starter Thread starter Michael Van Altena via .NET 247
  • Start date Start date
M

Michael Van Altena via .NET 247

Why doesn't the following add a row to the table dtTemp1?


System.Data.DataTable dtTemp1 = new System.Data.DataTable("Test1");

dtTemp1.Columns.Add("ColumnA", System.Type.GetType("System.String"));
dtTemp1.Columns.Add("ColumnB", System.Type.GetType("System.Decimal"));

System.Data.DataRow oRow = dtTemp1.NewRow();
oRow["ColumnA"] = "Test";
oRow["ColumnB"] = 0.25M;

dtTemp1.ImportRow(oRow); // This is the line that seems to do nothing, and throws no exceptions...
 
Why doesn't the following add a row to the table dtTemp1?


System.Data.DataTable dtTemp1 = new
System.Data.DataTable("Test1");

dtTemp1.Columns.Add("ColumnA",
System.Type.GetType("System.String"));
dtTemp1.Columns.Add("ColumnB",
System.Type.GetType("System.Decimal"));

System.Data.DataRow oRow = dtTemp1.NewRow();
oRow["ColumnA"] = "Test";
oRow["ColumnB"] = 0.25M;

dtTemp1.ImportRow(oRow); // This is the line that seems to do
nothing, and throws no exceptions...

Michael,

ImportRow() is used to copy rows from one DataTable to another. To
add a new row, change

dtTemp1.ImportRow(oRow)

to

dtTemp1.Rows.Add(oRow)
 
Back
Top