Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,

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..
Posted
Updated 7-May-12 23:04pm
v8
Comments
Praveen Meghwal 3-May-12 1:58am    
Does add/update functionality make separate entry in the table or they update an existing record.
ythisbug 3-May-12 2:52am    
thanks for ur reply..
existing..in tblCash column name csCash..
Rahul Rajat Singh 3-May-12 2:53am    
What have you tried so far?
ythisbug 3-May-12 2:59am    
i knw updating query..but for numberic i don knw how to gv query..
ythisbug 9-May-12 2:06am    
can any one help me.how to use this sp in aspx.cs page how to call .?

1 solution

SQL
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




Pass @status=1 for insert and @status=2 for update.
 
Share this answer
 
Comments
ythisbug 9-May-12 1:41am    
hi thanks can u tel me wats status here i have to add column ?o can u tel me how to call this in aspx.cs page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900