本文介绍了什么是它的错误我得到按摩失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=SHANTANU\\SQLEXPRESS;Initial Catalog=Inventry;Integrated Security=True");
SqlDataAdapter myadp = new SqlDataAdapter();
myadp.UpdateCommand = new SqlCommand();
myadp.UpdateCommand.Connection = con;
con.Open();
myadp.UpdateCommand.CommandText = "update purchase set quantity= quantity-'"+(qnt1.Text+qnt2.Text)+"' where item='"+(item1.Text+item2.Text)+"'";
int i = myadp.UpdateCommand.ExecuteNonQuery();
if (i ==1)
{
Response.Write("<script>alert('updated')</script>");
}
else
{
Response.Write("<script>alert('Failed')</script>");
}
con.Close();
}
推荐答案
if (i > -1)
{
Response.Write("<script>alert('updated')</script>");
}
else
{
Response.Write("<script>alert('Failed')</script>");
}
更新的解决方案
我希望这是串联有问题,所以试试这个
Updated solution
I hope this is something wrong with concatenation,So try this
"quantity= quantity-'"+(Convert.ToInt32(qnt1.Text)+Convert.ToInt32(qnt2.Text))+"' where item='"+(Convert.ToInt32(item1.Text)+Convert.ToInt32(item2.Text))+"'";
希望这会对你有所帮助。
问候,
RK
Hope this helps you a bit.
Regards,
RK
int value = Convert.ToInt32( qnt1.Text) + Convert.ToInt32( qnt2.Text);
int item = Convert.ToInt32( item1.Text) + Convert.ToInt32( item2.Text);
myadp.UpdateCommand.CommandText = "update purchase set quantity= quantity-"+ value+" where item='"+ item+"'";
这篇关于什么是它的错误我得到按摩失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!