求救!datatable怎么每次循环加一行?
datatable怎么每次循环加一行? --------------------编程问答-------------------- 把下面的代码放到你的循环里--------------------编程问答-------------------- DataRow dr=dt.NewRow();
var row = objDataTable.NewRow();
row["column1"] = "...";
row["column2"] = "...";
objDataTable.Rows.Add(row);
dr["Name"]="";
dt.Rows.Add(dr);
--------------------编程问答-------------------- table.Rows.Add(new object[] { value1, value2 }); --------------------编程问答--------------------
DataTable myTable = new DataTable();
foreach(DataRow myRow in Rows)
{
myTable.Rows.Add(myRow);
}
注:Rows是已知行的集合 --------------------编程问答-------------------- DataSet ds = new DataSet();
DataTable t = new DataTable("dataGrid1");
t.Columns.Add(new DataColumn("id", typeof(Int32)));
t.Columns.Add(new DataColumn("name", typeof(String)));
foreach (DataRow row in ds.Tables["dataGrid1"].Rows)
{
DataRow newrow = t.NewRow();
newrow["id"] = this.textBox1.Text.ToString();
newrow["name"] = this.textBox2.Text.ToString();
t.Rows.Add(newrow);
}
ds.Tables.Add(t);
dataGrid1.DataSource = ds.Tables["dataGrid1"]; --------------------编程问答-------------------- 大家看看,上面的直接就报错了,帮我看看为什么? --------------------编程问答-------------------- dt.ImportRow();
试试这个方法 --------------------编程问答-------------------- DataSet ds = new DataSet();与foreach (DataRow row in ds.Tables["dataGrid1"].Rows)
ds.Tables.Add(t);是同一个???
补充:.NET技术 , C#