C#中 查询DataTable是否包含某个特定的数据
作者:互联网
1、先定一个DataTable
private DataTable dtComp { get { return this["dtComp"] as DataTable; } set { this["dtComp"] = value; } }
2、创建datatable的行
dtComp = new DataTable(); dtComp.Columns.Add("SN", typeof(string)); dtComp.Columns.Add("Tag", typeof(string));
3、往datatable里面写入数据
DataRow drCompDataInput = dtComp.NewRow(); drCompDataInput["SN"] = lotDataTag.Lot; drCompDataInput["Tag"] = lotDataTag.Tag; dtComp.Rows.Add(drCompDataInput);
4、比较数据,返回结果为1,就代表有这个数据,正确。如果范围结果不为1,就代表没有找到该数据,则报错
if (dtComp.Select("SN ='" + lotData.Lot + "' and Tag = '" + lotData.Tag + "' ").Length != 1) { throw new Exception(TextMessage.Error.T00747("")); }
标签:dtComp,C#,drCompDataInput,查询,Add,Tag,SN,DataTable 来源: https://www.cnblogs.com/kelenote/p/15784241.html