-1
我創建了一個頁面,將數據從excel上傳到數據庫,在本地系統中工作正常。不在服務器中。請幫我解決這個錯誤。這是我的部分代碼..使用c導入excel使用c#
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
path = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
SaveLocation = Server.MapPath("~/Temp") + "\\" + path;
path = "Temp/" + path;
FileUpload1.PostedFile.SaveAs(SaveLocation);
//Import from Excel to database
System.Data.OleDb.OleDbDataAdapter MyCommand = default(System.Data.OleDb.OleDbDataAdapter);
System.Data.OleDb.OleDbConnection MyConnection = default(System.Data.OleDb.OleDbConnection);
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; " + "data source=" + SaveLocation + "; " + "Extended Properties=Excel 12.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
DS = new System.Data.DataSet();
MyCommand.Fill(DS);
DataTable dt = DS.Tables[0];
if (DS == null)
{
lblstatus.Text = "Problem occurred during uploading process... ";
}
else
{
foreach (DataRow row in dt.Rows)
{
DataSet5TableAdapters.sp_import_emp_generalTableAdapter TA = new DataSet5TableAdapters.sp_import_emp_generalTableAdapter();
TA.GetData(Convert.ToString(row["fldempid"]), Convert.ToString(row["fldlastname"]), Convert.ToString(row["fldfirstname"]), Convert.ToString(row["fldnickname"]),
Convert.ToString(row["fldDOB"]), Convert.ToString(row["fldmarital"]), Convert.ToString(row["fldgender"]), Convert.ToString(row["fldsmoker"]),
Convert.ToString(row["fldpic"]), Convert.ToString(row["fldaddress1"]), Convert.ToString(row["fldaddress2"]), Convert.ToString(row["fldcity"]),
Convert.ToString(row["fldstate"]), Convert.ToString(row["fldmobile"]), Convert.ToString(row["fldtele"]), Convert.ToString(row["fldwemail"]),
Convert.ToString(row["fldoemail"]), Convert.ToString(row["fldzip"]), Convert.ToString(row["fldtitle"]), Convert.ToString(row["fldjoindate"]),
Convert.ToString(row["fldspecification"]), Convert.ToString(row["fldcompany"]), Convert.ToString(row["fldgroup"]), Convert.ToString(row["flddept"]),
Convert.ToDouble(row["fldCTC"]), Convert.ToDouble(row["flddiv"]), Convert.ToDouble(row["fldbasic"]), Convert.ToDouble(row["fldhra"]),
Convert.ToDouble(row["fldconveyance"]), Convert.ToDouble(row["fldPF"]), Convert.ToDouble(row["fldesi"]), Convert.ToDouble(row["fldPT"]),
Convert.ToDouble(row["fldTDS"]), Convert.ToString(row["fldcafeteria"]), Convert.ToDouble(row["fldbasicvalue"]), Convert.ToDouble(row["fldhravalue"]),
Convert.ToDouble(row["fldconvalue"]), Convert.ToDouble(row["fldpfvalue"]), Convert.ToDouble(row["fldesivalue"]), Convert.ToDouble(row["fldptvalue"]),
Convert.ToDouble(row["fldtdsvalue"]), Convert.ToDouble(row["fldGrosspay"]), Convert.ToDouble(row["fldgrossearn"]), Convert.ToDouble(row["fldtotaldeduction"]),
Convert.ToDouble(row["fldnetpay"]), Convert.ToString(row["fldaccount"]), Convert.ToString(row["fldemployer"]), Convert.ToString(row["fldjobtitle"]),
Convert.ToString(row["fldstart"]), Convert.ToString(row["fldend"]), Convert.ToString(row["fldtotalexp"]), Convert.ToString(row["fldcomment"]),
Convert.ToString(row["fldedu"]), Convert.ToString(row["fldmajor"]), Convert.ToInt32(row["fldpassedout"]), Convert.ToString(row["fldskill"]),
Convert.ToString(row["fldexp"]), Convert.ToString(row["fldcomments"]), Convert.ToString(row["fldlanguage"]), Convert.ToString(row["fldfluency"]),
Convert.ToString(row["fldstatus"]));
}
System.Threading.Thread.Sleep(5000);
ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "<script language='javascript'>alert('Data Updated Successfully...');</script>", false);
lblstatus.Text = "Data updated successfully..";
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "<script language='javascript'>alert('Please select a file to upload');</script>", false);
}
}
catch (Exception e1)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "<script language='javascript'>alert('" + e1.Message + "');</script>", false);
}
請幫我解決這個錯誤....
您需要發佈錯誤也是如此。 – Candide 2012-04-06 05:33:55
沒有顯示錯誤。 – FDO 2012-04-06 05:35:10
數據未添加到服務器數據庫表中。但其在本地數據庫 – FDO 2012-04-06 05:36:49