2023年6月21日发(作者:)

C#使⽤list⽅法插⼊datatable中的数据到数据库前提:datatable⾥有值,数据库中有相应的表⼀、list,string⽅法 List lstSql = new List(); for (int i = 0; i < ; i++) { string ticketNo = [i]["票号"].ToString(); string actualcollect = [i]["实收款"].ToString().Replace("-", ""); string issueDate = Time([i]["出票⽇期"].ToString()).ToString("yyyy-MM-dd").Replace("-",""); string refundCharge = [i]["退票⼿续费(航空公司)"].ToString(); string approvalStatus = [i]["审核状态"].ToString(); sql = "insert intoCMB_Refund_TktNo_Ref(OnlineRecordTicketNo,Actualcollect,IssueDate,ApprovalStatus,RefundCharge)" + " values('{0}','{1}','{2}','{3}','{4}') "; sql = (sql, ticketNo, actualcollect, issueDate, approvalStatus, refundCharge); (sql); } eSqlTran(cmd); ();执⾏⽅法 public static int ExecuteSqlTran(List SQLStringList) { using (SqlConnection conn = new SqlConnection(connectionString)) { (); SqlCommand cmd = new SqlCommand { Connection = conn }; SqlTransaction tx = ransaction(); ction = tx; try { int count = 0; for (int n = 0; n < ; n++) { string strsql = SQLStringList[n]; if (().Length > 1) { dText = strsql; count += eNonQuery(); } } (); return count; } catch { ck(); return 0; } } }⼆、 List cmd = new List(); for (int i = 0; i < ; i++) { StringBuilder strSqlConfig = new StringBuilder(); ("insert intoCMB_Refund_TktNo_Ref(OnlineRecordTicketNo,Actualcollect,IssueDate,ApprovalStatus,RefundCharge)" + " values(@Tno,@Actcol,@Isdate,@Status,@Charge) "); try { SqlParameter[] paraConfig = { new SqlParameter("@Tno", ar, 10), new SqlParameter("@Actcol", ), new SqlParameter("@Isdate", ar, 8), new SqlParameter("@Status", ar, 8), new SqlParameter("@Charge", ) }; paraConfig[0].Value = [i]["票号"].ToString(); paraConfig[1].Value = [i]["实收款"].ToString().Replace("-", ""); paraConfig[2].Value = Time([i]["出票⽇期"].ToString()).ToString("yyyy-MM-dd").Replace("-", ""); paraConfig[3].Value = [i]["审核状态"].ToString(); paraConfig[4].Value = [i]["退票⼿续费(航空公司)"].ToString(); (new CommandInfo(ng(), paraConfig)); } catch (Exception ex) { ("写⼊数据库时发⽣错误:{0}", e); return; } } eSqlTran(cmd);

();执⾏⽅法 public static int ExecuteSqlTran(List cmdList) { using (SqlConnection conn = new SqlConnection(connectionString)) { (); using (SqlTransaction trans = ransaction()) { SqlCommand cmd = new SqlCommand(); try { int count = 0; //循环 foreach (CommandInfo myDE in cmdList) { string cmdText = dText; SqlParameter[] cmdParms = (SqlParameter[])ters; PrepareCommand(cmd, conn, trans, cmdText, cmdParms); if (NextType == veContine || NextType ==HaveContine) { if (r().IndexOf("count(") == -1) { ck(); return 0; }

object obj = eScalar(); bool isHave = false; if (obj == null && obj == ) { isHave = false; } isHave = 32(obj) > 0;

if (NextType == veContine && !isHave) { ck(); return 0; } if (NextType == HaveContine && isHave) { ck(); return 0; } continue; } int val = eNonQuery(); count += val; if (NextType == EffectRows && val == 0) { ck(); return 0; } (); } (); return count; } catch { ck(); throw; } } } }

2023年6月21日发(作者:)

C#使⽤list⽅法插⼊datatable中的数据到数据库前提:datatable⾥有值,数据库中有相应的表⼀、list,string⽅法 List lstSql = new List(); for (int i = 0; i < ; i++) { string ticketNo = [i]["票号"].ToString(); string actualcollect = [i]["实收款"].ToString().Replace("-", ""); string issueDate = Time([i]["出票⽇期"].ToString()).ToString("yyyy-MM-dd").Replace("-",""); string refundCharge = [i]["退票⼿续费(航空公司)"].ToString(); string approvalStatus = [i]["审核状态"].ToString(); sql = "insert intoCMB_Refund_TktNo_Ref(OnlineRecordTicketNo,Actualcollect,IssueDate,ApprovalStatus,RefundCharge)" + " values('{0}','{1}','{2}','{3}','{4}') "; sql = (sql, ticketNo, actualcollect, issueDate, approvalStatus, refundCharge); (sql); } eSqlTran(cmd); ();执⾏⽅法 public static int ExecuteSqlTran(List SQLStringList) { using (SqlConnection conn = new SqlConnection(connectionString)) { (); SqlCommand cmd = new SqlCommand { Connection = conn }; SqlTransaction tx = ransaction(); ction = tx; try { int count = 0; for (int n = 0; n < ; n++) { string strsql = SQLStringList[n]; if (().Length > 1) { dText = strsql; count += eNonQuery(); } } (); return count; } catch { ck(); return 0; } } }⼆、 List cmd = new List(); for (int i = 0; i < ; i++) { StringBuilder strSqlConfig = new StringBuilder(); ("insert intoCMB_Refund_TktNo_Ref(OnlineRecordTicketNo,Actualcollect,IssueDate,ApprovalStatus,RefundCharge)" + " values(@Tno,@Actcol,@Isdate,@Status,@Charge) "); try { SqlParameter[] paraConfig = { new SqlParameter("@Tno", ar, 10), new SqlParameter("@Actcol", ), new SqlParameter("@Isdate", ar, 8), new SqlParameter("@Status", ar, 8), new SqlParameter("@Charge", ) }; paraConfig[0].Value = [i]["票号"].ToString(); paraConfig[1].Value = [i]["实收款"].ToString().Replace("-", ""); paraConfig[2].Value = Time([i]["出票⽇期"].ToString()).ToString("yyyy-MM-dd").Replace("-", ""); paraConfig[3].Value = [i]["审核状态"].ToString(); paraConfig[4].Value = [i]["退票⼿续费(航空公司)"].ToString(); (new CommandInfo(ng(), paraConfig)); } catch (Exception ex) { ("写⼊数据库时发⽣错误:{0}", e); return; } } eSqlTran(cmd);

();执⾏⽅法 public static int ExecuteSqlTran(List cmdList) { using (SqlConnection conn = new SqlConnection(connectionString)) { (); using (SqlTransaction trans = ransaction()) { SqlCommand cmd = new SqlCommand(); try { int count = 0; //循环 foreach (CommandInfo myDE in cmdList) { string cmdText = dText; SqlParameter[] cmdParms = (SqlParameter[])ters; PrepareCommand(cmd, conn, trans, cmdText, cmdParms); if (NextType == veContine || NextType ==HaveContine) { if (r().IndexOf("count(") == -1) { ck(); return 0; }

object obj = eScalar(); bool isHave = false; if (obj == null && obj == ) { isHave = false; } isHave = 32(obj) > 0;

if (NextType == veContine && !isHave) { ck(); return 0; } if (NextType == HaveContine && isHave) { ck(); return 0; } continue; } int val = eNonQuery(); count += val; if (NextType == EffectRows && val == 0) { ck(); return 0; } (); } (); return count; } catch { ck(); throw; } } } }