dt = FM_HR_ShiftMaintenanceManager.GetCsvToDataTable(strConn, excelName,"XJSQMonthlyImportExcelData"); int iCount = dt.Rows.Count; StringBuilder sb = new StringBuilder(); if (dt != null) { int loop = Convert.ToInt32(Math.Floor((iCount / 100) * 1.0)); DlSoft.Liveflow.Common.Log.LogHelper.Logger.Write("loop :"+loop); if (loop < 1) { for (int j = 0; j < iCount; j++) { if (!string.IsNullOrEmpty(dt.Rows[j][1].ToString())) { sb.Append(dt.Rows[j][0].ToString() + "@@" + dt.Rows[j][1].ToString() + "$$"); } } ssql = string.Format(@"exec usp_UpdateXiuJiaSQMonthlyStatus '{0}'", sb.ToString()); int t = dbt.ExecuteNonQuery(ssql); } else { for (int k = 0; k < loop; k++) { for (int l = 0; l < 100; l++) { if (!string.IsNullOrEmpty(dt.Rows[l + k * 100][1].ToString())) { sb.Append(dt.Rows[l + k * 100][0].ToString() + "@@" + dt.Rows[l + k * 100][1].ToString() + "$$"); } } if (!string.IsNullOrEmpty(sb.ToString())) { ssql = string.Format(@"exec usp_UpdateXiuJiaSQMonthlyStatus '{0}'", sb.ToString()); int tt = dbt.ExecuteNonQuery(ssql); sb.Remove(0, sb.Length); } } for (int m = 0; m < iCount - loop * 100; m++) { if (!string.IsNullOrEmpty(dt.Rows[m + loop * 100][1].ToString())) { sb.Append(dt.Rows[m + loop * 100][0].ToString() + "@@" + dt.Rows[m + loop * 100][1].ToString() + "$$"); } } if (!string.IsNullOrEmpty(sb.ToString())) { ssql = string.Format(@"exec usp_UpdateXiuJiaSQMonthlyStatus '{0}'", sb.ToString()); int ttt = dbt.ExecuteNonQuery(ssql); } } }
获取excel数据
////// 获取excel数据导入.xlsxs /// /// 连接名称 /// exec地址 /// excel名字 /// exce表自定义名字 ///public static DataTable GetCsvToDataTable(string strConn, string excelName, string FillName) { OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); DataSet ds = new DataSet(); OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("select * from [" + excelName + "$]"), conn); //这里的表名参数,就是 CSV的完整文件名 odda.Fill(ds, FillName); conn.Close(); return ds.Tables[0]; }