大牛请进!上传excel表格,本地成功,服务器端不成功,为什么?
上传excel表格,本地成功,服务器端不成功,为什么?
本地能上传成功,为甚在服务器端不行呢?到服务器端的路径都是对的,但是就没有传到相应的文件夹,为什么啊?
protected DataTable getExcelDate()
{
if (conn.State.ToString() == "Closed")
{
conn.Open();
}
string onadvance = "exec sp_configure 'show advanced options',1 reconfigure";
string ondistributed = "exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure";
string offadvance = "exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure";
string offdistributed = "exec sp_configure 'show advanced options',0 reconfigure";
string thepath = Server.MapPath("~/NameList/");
FileUpload1.SaveAs(thepath + "\\" + FileUpload1.FileName);
string newpath = thepath +"\\"+ FileUpload1.FileName.ToString();
string sql = "select * from OpenDataSource('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=" + newpath + "',sheet1$)";
SqlCommand myCommand11 = new SqlCommand(onadvance, conn);
myCommand11.ExecuteNonQuery();
SqlCommand myCommand12 = new SqlCommand(ondistributed, conn);
myCommand12.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
SqlCommand myCommand31 = new SqlCommand(offadvance, conn);
myCommand31.ExecuteNonQuery();
SqlCommand myCommand32 = new SqlCommand(offdistributed, conn);
myCommand32.ExecuteNonQuery();
return ds.Tables[0];
}
------解决方案--------------------
1. 保存文件,要求有相应的权限;
2. 楼主的代码很奇怪,用oledb来读取excel吗?怎么没看到connection到excel文件????
------解决方案--------------------
路径要设置权限。