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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM