如何添加和减去值? [英] how to Add and minus values?

查看:75
本文介绍了如何添加和减去值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在sp中停留了一个查询.在我的aspx页面中,一个名为 txtMoney 的文本框和两个按钮
btnAdd和btnUpdate 此记录将保存到 tblCash.

认为现金是10000,我是指样本..同时添加5000,那么它应该增加到剩余金额10000 + 5000 = 15000.如果我单击 btnadd 按钮,它应该进行更新.从 tblCash 表中获取,所以每当我放点钱并且单击 btnupdate 按钮时,它都应减去现金总额..

任何人都可以帮助我创建sp ..
谢谢和问候..

我忘了提到tblCash中的列
tblCash包含cCash列,因此我想在添加时更新此列,并减少..任何人都可以建议我..

或有人可以建议我创建简单的查询..
像在更新中tblCash(cCash)values(@ Cash//所以在这里wat必须给我平均指的是要为相同列添加的数学查询,我是平均要更新)


@Mohd Wasif如何在aspx.cs页面中调用..i给了这样的查询



I stuck with one query in sp. In my aspx page one Text box named txtMoney and two buttons
btnAdd and btnUpdate this records is saving to tblCash.

think cash is 10000 i mean sample..while adding 5000 then it should add to that remaining amount 10000+5000=15000.it should update if i click btnadd button..and update button is to less amount from tblCash table so whenever i place some money and if i click btnupdate button it should be minus from total cash..

can any one help me to create sp..
thanks and regards..

i forgot to mention column in tblCash
tblCash contains cCash column so i want to update this column while adding and less..can any one suggest me..

or can any one suggest me to create simple query..
like in update tblCash(cCash)values(@Cash//so here wat have to give i mean mathematic query to add for same colum i mean update)


@Mohd Wasif how to call in aspx.cs page..i gave query like this

protected void btnAdd_Click(object sender, EventArgs e)
   {

       txtAmount.Text = "";

       SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());
       con.Open();
       //SqlCommand cmd = new SqlCommand("Update tblCash set cCash=cCash+@Cash where cID=@ID");
       SqlCommand cmd = new SqlCommand();
       cmd.Connection = con;
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.CommandText = "usp_InsertUpdateRecord";

       SqlParameter cash=new SqlParameter("@Cash",SqlDbType.Decimal);
       cash.Value =txtAmount.Text;
       cmd.Parameters.Add(cash);


       cmd.ExecuteNonQuery();

      lblMessage.Text = "Amount Added";
      txtAmount.Text = "";
      lblMessage.Text = "";
      con.Close();
      cmd.Dispose();

   }


但出现无法将参数值从字符串转换为小数的错误".
您能否建议我再次修改?.


but am Getting Error like Failed to convert parameter value from a String to a Decimal.
can u suggest me wat have to modify again..

推荐答案

create proc my_sp_Insert_Update_Record
@status int,
@money numeric (18,2)
as
if(@status=1)
begin
update tblCash set Amount=Amount+@money
end
else if (@status=2)
begin
declare @balanceAmount numeric(18,2)
select @balanceAmount=Amount from tblCash
if(@money>@balanceAmount)
begin
Print 'You can not update amount as Balance amount is less than input Amount'
end
else
begin
update tblCash set Amount=Amount-@money
end
end





传递@ status = 1进行插入,传递@ status = 2进行更新.





Pass @status=1 for insert and @status=2 for update.


这篇关于如何添加和减去值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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