for (int i = 0; i < 4; i++) { DataRow r = table.NewRow(); r[0] = i.ToString(); table.Rows.Add(r); } ??????????? for (int i = 0; i < 4; i++) { DataRow r = table.NewRow(); r[i] = i.ToString(); table.Rows.Add(r); }
DataTable table = new DataTable(); DataColumn col = new DataColumn("id"); table.Columns.Add(col); for (int i = 0; i < 16; i++) // 为什么这里改成16以上的数字就不管用了? { DataRow r = table.NewRow(); r[0] = i.ToString(); table.Rows.Add(r); } DataRow[] row = table.Select("id=2"); if (row.Length > 0) { foreach (DataRow rr in row) { table.Rows.Remove(rr); } } foreach (DataRow r1 in table.Rows) { Console.WriteLine(r1[0].ToString()); Console.WriteLine(); } Console.ReadKey();
这两个方法不符合我的需求Rows.Remove(1)
Rows.Remove(datarow)
DataTable table = new DataTable();
DataColumn col = new DataColumn("id");
table.Columns.Add(col);
for (int i = 0; i < 4; i++)
{
DataRow r = table.NewRow();
r[0] = i.ToString();
table.Rows.Add(r);
} DataRow[] row = table.Select("id=2"); if (row.Length > 0)
{
foreach (DataRow rr in row)
{
table.Rows.Remove(rr);
}
}
foreach (DataRow r1 in table.Rows)
{
Console.WriteLine(r1[0].ToString());
Console.WriteLine();
}
Console.ReadKey();
直接用table.remove(row)应该就可以
DataRow[] rows = dt.Select(string.Format("name='{0}'", "aa"), "");
if (rows.Length == 1) { dt.Rows.Remove(rows[0]); }
{
DataRow r = table.NewRow();
r[0] = i.ToString();
table.Rows.Add(r);
}
???????????
for (int i = 0; i < 4; i++)
{
DataRow r = table.NewRow();
r[i] = i.ToString();
table.Rows.Add(r);
}
DataTable table = new DataTable();
DataColumn col = new DataColumn("id");
table.Columns.Add(col);
for (int i = 0; i < 16; i++) // 为什么这里改成16以上的数字就不管用了?
{
DataRow r = table.NewRow();
r[0] = i.ToString();
table.Rows.Add(r);
} DataRow[] row = table.Select("id=2"); if (row.Length > 0)
{
foreach (DataRow rr in row)
{
table.Rows.Remove(rr);
}
}
foreach (DataRow r1 in table.Rows)
{
Console.WriteLine(r1[0].ToString());
Console.WriteLine();
}
Console.ReadKey();
对数据集产生真实的影响
2.DataTable.DefaultView.RowFilter属性:
不影响数据集自己选择