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("")); }