相关代码是:
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(); // 单号
string NameCode = dt.Rows[i][5].ToString(); // 客户编号
string Demand = dt.Rows[i][6].ToString(); // 需求
string DeliveryDate = dt.Rows[i][7].ToString(); // 交期
string Mark = dt.Rows[i][8].ToString(); // 料
string Height = dt.Rows[i][9].ToString(); // 厚
string Width = dt.Rows[i][10].ToString(); // 宽
}
错误提示:myda.Fill(myds); 外部表不是预期的格式?
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(); // 单号
string NameCode = dt.Rows[i][5].ToString(); // 客户编号
string Demand = dt.Rows[i][6].ToString(); // 需求
string DeliveryDate = dt.Rows[i][7].ToString(); // 交期
string Mark = dt.Rows[i][8].ToString(); // 料
string Height = dt.Rows[i][9].ToString(); // 厚
string Width = dt.Rows[i][10].ToString(); // 宽
}
错误提示:myda.Fill(myds); 外部表不是预期的格式?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货