什么是它的错误我得到按摩失败 [英] What Is Wrorg In It I M Getting Failed Massage

查看:82
本文介绍了什么是它的错误我得到按摩失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
}

推荐答案

嗨Shantanu,



如果你使用ExecuteNonQuery(),然后



对于UPDATE,INSERT和DELETE语句,返回值是受命令影响的行数。



所以我认为更新的行数可能大于1,所以它在你的情况下会出错。

试试这个

Hi Shantanu,

If you use ExecuteNonQuery(), then

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

So I think the number of rows updated may be greater than 1 so its error in your condition.
Try this
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


其中item ='+(item1.Text + item2.Text)+'

看起来很奇怪。我不希望项目的标识符分成两个文本框。

你想更新两行(即两个项目的数据)?然后在一次交易中发送两个单独的更新请求。
where item='"+(item1.Text+item2.Text)+"'
That looks very strange. I would not expect the identifier of the item to be split over two textboxes.
Do you want to update two rows (i.e. the data for two items)? Then send two individual update requests, in one transaction.


试试这个





try this


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+"'";


这篇关于什么是它的错误我得到按摩失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆