gpt4 book ai didi

c# - 数据表中的验证

转载 作者:行者123 更新时间:2023-11-30 23:20:19 25 4
gpt4 key购买 nike

我在这里将大量数据放入超过 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com