ASP.net excel 导入 SQL是出现外部表不是预期的格式?
相关代码是:
protected void Button1_Click(object sender, EventArgs e)
{
string strpath = Server.MapPath( "excelfile ") + DateTime.Now.ToString( "yyyymmddhhmmss ") + ".xls ";//确定一个文件名
fileup.PostedFile.SaveAs(strpath);
string mystring = "provider = microsoft.jet.oledb.4.0 ; data source = " + strpath + ";extended properties=excel 8.0 ";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myda = new OleDbDataAdapter( "select * from [sheet1$] ", cnnxls);
DataSet myds = new DataSet();
myda.Fill(myds);
try
{
Edit_data(myds.Tables[0]);
}
catch (Exception ex)
{
Label2.Text = ex.Message;
}
}
protected void Edit_data(DataTable dt)
{
for (int i = 0; i < dt.Rows.Count; i++)//逐行加
{
string LotNo = dt.Rows[i][1].ToString(); // 订单批号
string Enterprise = dt.Rows[i][2].ToString(); // 业
string CardNmae = dt.Rows[i][3].ToString(); // 客户
string CardCode = dt.Rows[i][4].ToString(); // 单号
&