如何删除DataTable里面的记录 我想在Datatable绑定GridView之前,删除一些不显示的数据,怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataTable newtable = set.Tables[0]; try { //这是过滤的条件 foreach (DataRow dataRow in newtable.Rows) { if (((string)dataRow["ISPRIME"] == "1") && ((string)dataRow["ISLOCK"] == "0") && ((string)dataRow["ISTOP"] == "0")) { } else { dataRow.Delete(); } } //清除DS中所有的表 set.Tables.Clear(); //把新表newtable加到DATASET中 set.Tables.Add(newtable); //把GridView1的数据源清空 GridView1.DataSource = null; //把新表newtable赋给GridView1的数据源 GridView1.DataSource = set; //把新表newtable与GridView1数据绑定 GridView1.DataBind();随便写的一个 筛选一下DataRow[] dr = DataTable.Select("你要筛选的条件");gridview.datasource = dr; 为什么不直接在sql里将数据去除掉呢? DataView dv = new DataView(dt);dv.RowFilter = "UserType=1";dataGrid.DataSource = dv;dataGrid.DataBind(); DataRow[] drs = DataTabl1.Select("id=2 or id=4"); for( int i=0 ; i<drs.Count ; i++ ) { DataTable1.Rows.Remove( drs[i] ); 你是想删除还是想过滤?删除:datatable.Rows.Remove()或RemoveAt() UP,LZ应该就是这个意思,进行判断,然后根据索引RemoveAt()删除指定项 上面有很多思路了,自己去实现吧,也就是重新把需要的数据在datatable里面绑定一下 过滤DataView dv = new DataView(dt); dv.RowFilter = "UserType=1"; dataGrid.DataSource = dv; dataGrid.DataBind(); 删除: datatable.Rows.Remove()或RemoveAt()别忘了datatable.AcceptChanges(); 远程读取xml + 条件 跪求 决策分析系统 急急急急急急急急急急急急急急 为什么在web设计界面有时有<from></from>? 我的数据库总是被人改怎么办? WCF The remote server returned an error: (413) Request Entity Too Large. 如何在表格各单元格中分布Checkboxlist? 如何在DataGrid的超级链接列绑定两个url字段? 关于DATASET的一个疑问? 我怎样判断究竟按的是那个linkbutton呢? ASP.NET的设计页不能使用了 提交后如何遍历Repeater 中的 CheckBox ????
DataTable newtable = set.Tables[0];
try
{
//这是过滤的条件
foreach (DataRow dataRow in newtable.Rows)
{
if (((string)dataRow["ISPRIME"] == "1") && ((string)dataRow["ISLOCK"] == "0") && ((string)dataRow["ISTOP"] == "0"))
{
}
else
{
dataRow.Delete();
}
}
//清除DS中所有的表
set.Tables.Clear();
//把新表newtable加到DATASET中
set.Tables.Add(newtable);
//把GridView1的数据源清空
GridView1.DataSource = null;
//把新表newtable赋给GridView1的数据源
GridView1.DataSource = set;
//把新表newtable与GridView1数据绑定
GridView1.DataBind();
随便写的一个
DataRow[] dr = DataTable.Select("你要筛选的条件");gridview.datasource = dr;
dv.RowFilter = "UserType=1";dataGrid.DataSource = dv;
dataGrid.DataBind();
for( int i=0 ; i<drs.Count ; i++ )
{
DataTable1.Rows.Remove( drs[i] );
datatable.Rows.Remove()或RemoveAt()
DataView dv = new DataView(dt);
dv.RowFilter = "UserType=1"; dataGrid.DataSource = dv;
dataGrid.DataBind(); 删除:
datatable.Rows.Remove()或RemoveAt()
别忘了
datatable.AcceptChanges();