开发者

Cannot add new Row to Datatable

开发者 https://www.devze.com 2023-03-01 10:00 出处:网络
开发者_高级运维 Merged with Add new Row to DataTable. I am trying to add two new Rows to a DataTable. My DataSource consist of a Database with one Table (FooTable) and one column (FooName)
开发者_高级运维 Merged with Add new Row to DataTable.

I am trying to add two new Rows to a DataTable. My DataSource consist of a Database with one Table (FooTable) and one column (FooName).

See following code. Only the first Row "Mary" is added and displayed on my DataGrid, but not the second row "Jesus". No exception occurs. Why doesn't it work and what is the correct way to add multiple rows dynamically to DataTable?

/* dg1 = DataGrid; ds = DataSet */
dg1.ItemsSource = ds.Tables;

/* dt = DataTable */
DataRow newRow = dt.NewRow();
newRow["FooName"] = "Mary";
dt.Rows.Add(newRow);

/* add another row to data table */
DataRow newRow2 = dt.NewRow();
newRow2["FooName"] = "Jesus";
dt.Rows.Add(newRow2);
0

精彩评论

暂无评论...
验证码 换一张
取 消