更新时间:2023-11-29 08:20:52
",oconn); OleDbDataAdapter da = 新 OleDbDataAdapter(cmd); oconn.Open(); da.Fill(ds); oconn.Close();
", oconn); OleDbDataAdapter da = new OleDbDataAdapter(cmd); oconn.Open(); da.Fill(ds); oconn.Close();
where ds is a datatable.
DataTable dt= ds.Table[0];
int numberOfColumns = dt.Columns.Count;
bool IsAllInt =true;
// go through each row
foreach (DataRow dr in dt.Rows)
{
// go through each column in the row
for (int i = 0; i < numberOfColumns; i++)
{
int val;
if(!int.TryParse(dr[i].ToString(), out val))
{
IsAllInt =false;
break;
}
}
}
//check the value of IsAllInt
从XLS文件加载数据之前,您应先将Column
对象的类型指定为int,然后将DataTable
及其列创建为try-catch-finally
阻止,您应该从XLS文件中的数据中加载数据,如果XLS中的数据中存在错误,则会引发某些异常.
Before to load the data from XLS file you should create yourDataTable
and its columns by specifying the type of theColumn
objects as int then, into atry-catch-finally
block you should load your data from your data from XLS file and if there errors in the data from XLS some exception will be thrown.