如果DataTable中gid列 包含数据
6,9,10,12,13,19
则DataTable中DDName
显示为“-”,用C#怎么写呢
如楼上,先定义数组:string[] keys=new string[]{"6","9","10","12","13","19"}。
代码如下:
string[] keys=new string[]{"6","9","10","12","13","19"}; System.Data.DataTable dt = new System.Data.DataTable(); for (var i = 0; i < dt.Rows.Count; i++) { if (keys.Contains(dt.Rows[i]["gid"].ToString())) { dt.Rows[i]["gid"] = "-"; } }
if(DataTable.Rows[0]["gid"].indexof("6,9,10,12,13,19")>-1)
{
DataTable.Rows[0]["DDName"] = "-";
}
遍历集合,DataTable.Select("gid in ('')")要比DataTable.Rows要好。。。