![]() |
#2
爱编程的小猪2007-09-29 09:58
给你个我写的仅供参考: protected void Button1_Click(object sender, EventArgs e) string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);//获取文件名 string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);//获取文件名中的扩展名 if (type == "xls")//判断扩展名 this.FileUpload1.PostedFile.SaveAs(Server.MapPath("up") + "\\" + fileName);//记录文件名到服务器相对应的文加中 } for (int i = 0; i < rows; i++) |
网站未发布时,我可以把excel表中的数据成功的导入到sql数据库中;发布后,不能导入,这是怎么回事??;
难道是取文件路径时出错了?做程序时,我取excel文件路径用的是以下语句,请大家帮忙看看啊
string filePath = this.FileUpload1.PostedFile.FileName;
filePath = this.FileUpload1.PostedFile.FileName;
if (filePath == "")
{
Response.Write("<script>alert('请先选择文件')</script>");
return;
}
string connExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=Excel 8.0";
{
OleDbConnection oleDbConnection = new OleDbConnection(connExcel);
oleDbConnection.Open();
..................
}