您好,
我上传的Excel文件,复制到数据集。
使用此代码,
DataSet ds = new DataSet();
OleDbCommand excelCommand = new OleDbCommand();
OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
string excelConnStr;
if (Extension != ".xlsx")
{
excelConnStr = String.Format("Provider=Microsoft.Jet.OleDb.4.0; Data Source = {0}; Extended Properties =\"Excel 8.0", filelocation);
}
else
{
excelConnStr = String.Format("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = {0}; Extended Properties =\"Excel 12.0", filelocation);
}
OleDbConnection excelConn = new OleDbConnection(excelConnStr);
excelConn.Open();
DataTable dt= new DataTable();
excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);
excelDataAdapter.SelectCommand = excelCommand;
excelDataAdapter.Fill(dt);
数据表中的记录是不正确的。
如果Excel有1行,表中有3行..
我们怎样才能解决这个问题?