c# - 数据表中的验证

标签 c# asp.net excel validation oledbdataadapter

我在这里将大量数据放入超过 5000 条的表中

  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、性别、空值等的验证

最佳答案

我认为你应该使用这段代码

 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 
                         }
                  }
                }

            }

关于c# - 数据表中的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39805379/

相关文章:

c# - 如何获取 Entity Framework 中的特定列

arrays - VBA - 匹配2个排序字符串数组,其中某些元素不匹配 - 优化

c# - AutoResetEvent 和 Mutex 有什么区别

javascript - 如何在发布 html 表单时进行 Base64 编码?

c# - 使用 MVVM LIGHT (WPF) 在 UserControl 中导航

VBA如何声明包含不同数据类型元素的数组

excel - 如何生成常规 Excel 公式作为查询结果?

c# - “RouteCollection”不包含 'MapMvcAttributeRoutes' 的定义

c# - 如何确定网络应用程序的上行/下行延迟

javascript - 如何将 'attach' ASP.NET 字节数组转换为表单上的 'file' 类型输入字段?