更新时间:2023-12-01 09:57:04
当您创建新的datatable时,它是空的 - 即没有行。这就是为什么在索引 0
找不到行。您应该手动创建和添加行。
When you create new datatable, it is empty - i.e. there is no rows. That's why you can't find row at index 0
. You should create and add rows manually.
使用 DataTable.NewRow 方法来创建与您的datatable相同的列(即相同的模式)的新行:
Use DataTable.NewRow method to create new row with same columns (i.e. same schema) as your datatable:
DataRow row = obj_dt_grdvw.NewRow(); // create new row
row["_Pur_Product_Id"] ="12"; // set field values
row["Product_pur_Name"] ="milk";
obj_dt_grdvw.Rows.Add(row); // add this new row to table rows