帮我看看这段代码对吗??
string strPath,FileName;
strPath=File1.PostedFile.FileName;
FileName=strPath.Substring(strPath.LastIndexOf("\\")+1);
if(strPath == "")
{
Response.Write("<script>alert('请先选择文件')</script>");
return;
}
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + strPath + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
try
{
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [常规产品清册$]", objConn); //这里的sheet用不用带[]和里面的$阿??
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet dsolb = new DataSet();
objAdapter1.Fill(dsolb,"常规产品清册"); //这里是写sheet吗??
DataGrid1.DataSource = dsolb.Tables[0].DefaultView;
DataGrid1.DataBind();
}
catch(Exception ee)
{
Response.Write("<script>alert('请先关闭文件')</script>");
return;
}
finally
{
objConn.Close();
}
[此贴子已经被作者于2006-9-6 15:55:32编辑过]
新建的群(C#):23384106 验证注明