日期:2014-05-18  浏览次数:20862 次

怎么同时往两条表中插入数据
怎么同时往两条表中插入数据

  我在添加一条数据(表A)的时候,如果操作成功的话,将表B中的某条数据进行修改

public static bool InsertProject(NameValueCollection nvc, string userID, string userName, string departmentID, string departName)
{
  int count = 0;
  string isloan = "";
  string loanid = "";
  string type = nvc["expenseType"];
  if (nvc["loanid"] == null) { loanid = "0"; isloan = "否"; } else { loanid = nvc["loanid"]; isloan = "是";}

  string sqlLoan = "update tb_loanBill set ispayment=:ispayment where loanid in" + '(' + (loanid) + ')';

  string sqlproject = "insert into tb_expenseaccount(expenseid,expensename,departmentid,departmentname,expenseuid,expenseuname,bankrollpurpose,expensestate,expensedate,expensetype,promanagername,amountofmoney,isloan,loanid,fangzu,phone,moble,chailv,yan,jiu,lipin,yunfei,cailiao,buchang,oil,street,parking,fix,shenghuo,bangong,qita) "
  + "values(:expenseid,:expensename,:departmentid,:departmentname,:expenseuid,:expenseuname,:bankrollpurpose,:expensestate,:expensedate,:expensetype,:promanagername,:amountofmoney,:isloan,:loanid,:fangzu,:phone,:moble,:chailv,:yan,:jiu,:lipin,:yunfei,:cailiao,:buchang,:oil,:street,:parking,:fix,:shenghuo,:bangong,:qita)";


  string strProject = "";
  if (!string.IsNullOrEmpty(nvc["txt_buchang"])) { strProject = "补偿:" + nvc["txt_buchang"] + ';'; }
  if (nvc["txt_fangzu"] != "") { strProject += "房租费:" + nvc["txt_fangzu"] + ';'; }
  if (nvc["txt_dianhua"] != "") { strProject += "电话费:" + nvc["txt_dianhua"] + ';'; }
  if (nvc["txt_chailv"] != "") { strProject += "差旅费:" + nvc["txt_chailv"] + ';'; }
  if (nvc["txt_zhaodai"] != "") { strProject += "招待费:" + nvc["txt_zhaodai"] + ';'; }
  if (nvc["txt_lipin"] != "") { strProject += "礼品:" + nvc["txt_lipin"] + ';'; }
  if (nvc["txt_yunfei"] != "") { strProject += "运费:" + nvc["txt_yunfei"] + ';'; }
  if (nvc["txt_cailiao"] != "") { strProject += "材料费:" + nvc["txt_cailiao"] + ';'; }
  if (nvc["txt_qiche"] != "") { strProject += "汽车费:" + nvc["txt_qiche"] + ';'; }
  if (nvc["txt_shenghuo"] != "") { strProject += "生活用品:" + nvc["txt_shenghuo"] + ';'; }
  if (nvc["txt_bangong"] != "") { strProject += "办公用品:" + nvc["txt_bangong"] + ';'; }
  if (nvc["txt_qita"] != "") { strProject += nvc["txt_qita"] + '。'; }

  DataParameter[] pList = new DataParameter[]
  {
  new DataParameter("expenseid",DbType.Int32,18,Common.Common.GetDBpk("tb_expenseaccount")),
  new DataParameter("expensename",DbType.String,50,Common.Common.ParaDecode(nvc["expenseName"])),
  new DataParameter("departmentid",DbType.Int32,18,departmentID),
  new DataParameter("departmentname",DbType.String,18,departName),
  new