2016-10-01 52 views
0

在這裏我把一個大容量的數據表的更多的則5000+驗證DataTable中

using (OleDbConnection excel_con = new OleDbConnection(conString)) 
     { 
      excel_con.Open(); 
      string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString(); 
      DataTable dtExcelData = new DataTable(); 





      dtExcelData.Columns.AddRange(new DataColumn[10] { 

//this are my columns of records 

      new DataColumn("Employee Code",typeof(string)), 
      new DataColumn("Employee Type", typeof(int)), 
      new DataColumn("First Name", typeof(string)), 
      new DataColumn("Last Name", typeof(string)), 
      new DataColumn("Gender",typeof(string)), 
      new DataColumn("Email ID", typeof(string)), 
      new DataColumn("Mobile No#", typeof(string)), 
      new DataColumn("Current Address", typeof(string)), 
      new DataColumn("Permanent Address", typeof(string)), 
      new DataColumn("Status",typeof(string)) 
     } 
      ); 


      using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con)) 
      { 
       oda.Fill(dtExcelData); 


      } 
      excel_con.Close(); 

現在插入前或在數據表 我要檢查手機號碼,電子郵件ID,性別的驗證插入後,空值等

回答

0

使用參考DataTable初始化的DataView類。 將過濾器選項寫入DataView。

+0

你可以用例或代碼解釋???? – Aamir

0

我認爲你應該使用這個代碼

using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con)) 
      { 
       oda.Fill(dtExcelData); 
       if(dtExcelData.rows.count<0) 
       { 
       for(int i=0;i<dtExcelData.rows.count;i++) 
       { 
        string mobno=dtExcelData.rows[i]["Mobile No#"].tostring(); 
        if(mobno=="") 
        { 
         //code here 
         } 
        } 
       } 

      }