private void ClientFileToServerTemp() { #region try { //設定頁面狀態 this.ErrorMsgLabel1.Text = ""; gv_ErrorData.Visible = false; LockPage(); string s_UploadPath = string.Empty; string s_BackPath = string.Empty; string s_LoginUser = string.Empty; ArrayList arl_FileUpload_Return = null; ArrayList arl_FileToTmp_Return = null; BCO.VDS_IVM38_BCO bco = new BCO.VDS_IVM38_BCO(ConntionDB); #region 上傳檔案到AP端 //取得要上傳的路徑 s_UploadPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + "\\IVM\\"; s_LoginUser = Session["UID"].ToString(); arl_FileUpload_Return = bco.FileUpload(s_UploadPath, this.FileUpload1, s_LoginUser); #endregion if (arl_FileUpload_Return[0].ToString() == "FALSE")//檔案上傳至AP端錯誤 { #region this.ErrorMsgLabel1.Text = "檔案上傳至AP端錯誤";//檔案上傳至AP端錯誤,後面直接不做了 #endregion } else if (arl_FileUpload_Return[0].ToString() == "TRUE")//檔案上傳至AP端正常 { #region #region 讀取 Excel 資料 OleDbConnection oleConnection = null; DataSet ds_Excel = new DataSet(); try { String connString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source =" + arl_FileUpload_Return[1].ToString() + ";Extended Properties=Excel 8.0;"; oleConnection = new OleDbConnection(connString); oleConnection.Open(); OleDbCommand oleCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", oleConnection); OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCommand); oleAdapter.Fill(ds_Excel); #region 請注意如果EXCEL檔欄位有值,但到DB卻沒有資料 //請修改,機碼 HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows 值 //預設是 8, 表示會先讀取前 8 列來決定每一個欄位的型態, 所以如果前 8 列的資料都是數字, 到了第 9 列以後出現的文字資料都會變成 null //如果要解決這個問題, 只要把 TypeGuessRows 機碼值改成 0 #endregion } catch (Exception ex) { this.Response.Write(ex.Message); } finally { if (oleConnection != null) { oleConnection.Close(); oleConnection.Dispose(); } } #endregion #region 將檔案匯入TmpTable int N_TMP_CNT = 0; int N_TAB_CNT = 0; string ErrorMsg = ""; DataTable dt = ds_Excel.Tables[0]; int N_UPLOAD = dt.Rows.Count; arl_FileToTmp_Return = bco.FileToTmp(dt, null, arl_FileUpload_Return[3].ToString(), Session["UID"].ToString()); #endregion //上傳結果 this.UploadStatusPanel1.UploadSum = Convert.ToInt32(arl_FileToTmp_Return[4].ToString()); this.UploadStatusPanel1.UploadOK = Convert.ToInt32(arl_FileToTmp_Return[4].ToString()) - Convert.ToInt32(arl_FileToTmp_Return[5].ToString()); this.UploadStatusPanel1.UploadNG = Convert.ToInt32(arl_FileToTmp_Return[5].ToString()); //匯入結果 this.UploadStatusPanel1.ImportSum = Convert.ToInt32(arl_FileToTmp_Return[1].ToString()); this.UploadStatusPanel1.ImportOK = Convert.ToInt32(arl_FileToTmp_Return[2].ToString()); this.UploadStatusPanel1.ImportNG = Convert.ToInt32(arl_FileToTmp_Return[3].ToString()); #endregion } unLockPage(); } catch (Exception ex) { this.ErrorMsgLabel1.Text = ex.Message.Split(Environment.NewLine.Replace(Environment.NewLine, "~").ToCharArray())[0]; //直接取第一個 unLockPage(); } #endregion }