关于ASP.NET满足条件下的插入记录
protected void btnClickOK_Click(object sender, EventArgs e){
string StoreID = this.txtStoreID.Text.Trim();
string StoreDate = this.txtStoreDate.Text;
string StoreType = this.ddlStoreType.Text.Trim();
string StorePlace = this.ddlStorePlace.SelectedValue.ToString();
string Sign = this.txtSign.Text.Trim();
string BuyDate = this.txtBuyDate.Text.Trim();
string BuyDepartment = this.ddlDepartment.SelectedValue.ToString();
string BuyMan = this.txtBuyMan.Text.Trim();
string Ratify = this.txtRatify.Text.Trim();
string Remark = this.txtRemark.Text.Trim();
string WzID = this.lnkWzID.Text.ToString();
string Name = this.txtName.Text.Trim();
string Model = this.txtModel.Text.Trim();
string Spec = this.txtSpec.Text.Trim();
string Card = this.txtCard.Text.Trim();
string UnitPrise = this.txtUnitPrise.Text.Trim();
string Unit = this.ddlUnit.SelectedValue.ToString();
string Amount = this.txtAmount.Text.Trim();
string Pay = this.txtPay.Text.Trim();
string CustomerID = this.ddlCustomer.SelectedValue.ToString();
string Customer = this.ddlCustomer.SelectedItem.Text;
string Address = this.txtAddress.Text.Trim();
string Phone = this.txtPhone.Text.Trim();
string LinkMan = this.txtLinkMan.Text.Trim();
try
{
bool b=DB.ExSql("insert into tb_Store values('" + StoreID + "','" + StoreDate + "', '" + StoreType + "', '" + StorePlace + "', '" + Sign + "', '" + BuyDate + "', '" + BuyDepartment + "','" + BuyMan + "','" + Ratify + "','" + Remark + "')");
if(b)
DB.ExSql("insert into tb_StoreDetails values('" + StoreID + "','" + WzID + "','" + Name + "','" + Model + "','" + Spec + "','" + Card + "'," + UnitPrise + ",'" + Unit + "','" + Amount + "'," + Pay + ",'" + CustomerID + "','" + Customer + "','" + Address + "','" + Phone + "','" + LinkMan + "') "); //使页面恢复初始状态
this.clear();
SqlConnection conn = DB.GetCon();
conn.Open();
AutoID(conn);//根据数据库中的记录数自动产生一个数作为入库单ID
this.lnkWzID.Text = "物资编号";
}
catch (SqlException oe)
{
Response.Write( "<script language='javascript'>alert('"+oe.Message+"')</script>");
}
上面的try{}里面的满足第一个插入记录后,为何第二条插入操作无法执行,数据库里也无相关的插入记录!!!!!!!!!!!!!!!! --------------------编程问答-------------------- try掏出异常吗? --------------------编程问答-------------------- 是否违法约束呢?造成这种情况的问题有很多 --------------------编程问答-------------------- 找不到插入数据库的执行代码在哪里。 --------------------编程问答-------------------- 第二条sql插入语句有错误,有字符串未被加“'”.
DB.ExSql("insert into tb_StoreDetails values('" + StoreID + "','" + WzID + "','" + Name + "','" + Model + "','" + Spec + "','" + Card + "'," + UnitPrise + ",'" + Unit + "','" + Amount + "'," + Pay + ",'" + CustomerID + "','" + Customer + "','" + Address + "','" + Phone + "','" + LinkMan + "') "); --------------------编程问答-------------------- DB.ExSql("insert into tb_StoreDetails values('" + StoreID + "','" + WzID + "','" + Name + "','" + Model + "','" + Spec + "','" + Card + "'," + UnitPrise + ",'" + Unit + "','" + Amount + "'," + Pay + ",'" + CustomerID + "','" + Customer + "','" + Address + "','" + Phone + "','" + LinkMan + "') "); --------------------编程问答-------------------- 强烈建议楼主改用参数化SQL,那么多东西拼起来可读性非常差,而且不安全。
补充:.NET技术 , ASP.NET