Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
hi
in my sql table tblCash contains cCash and cDate
so while adding am saving with + for positive value and - for negative value
and am getting total sum like Select SUM(cCash) from tblCash
so am getting total cash..this cash i want to display in Label..whenver i add + or - value it should refresh and shw the current sum..
can any one suggest me.??

or suggest me in ur way.like total cash i want to disply in label o textbox..

thanks

i tried like this
in cash.aspx.cs
private void GetSum()
    {
        string Sum;
        Sum = tbCash.Text;
        con.Open();

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_SumCash";     
        SqlParameter pSum = new SqlParameter("@Sum", SqlDbType.Int);
        pSum.Direction = ParameterDirection.Output;

        cmd.Parameters.Add(pSum);
        lblTotalCash.Text = pSum.Value.ToString();

        cmd.ExecuteNonQuery();

        con.Close();
    }


and this is my sp
SQL
alter PROCEDURE usp_SumCash
@Sum int Output


AS
BEGIN
set  @Sum=(Select SUM(cCash) from tblCash
where cCash=@Sum)


SET NOCOUNT ON;


END


and am getting error..'
object refernce is not set to an object of an instance..
Posted
Updated 24-May-12 6:51am
v3
Comments
[no name] 24-May-12 15:35pm    
You are not getting any error, you are getting an exception. Can you tell me, in which line, you faced the exception. The line should be highlighted in yellow.
ythisbug 25-May-12 0:34am    
lblTotalCash.Text = pSum.Value.ToString();

THIS LINE AM GETTING ERROR
Technoses 26-May-12 6:35am    
you should use
cmd.ExecuteNonQuery();
before below line

lblTotalCash.Text = pSum.Value.ToString();

Assuming you are using DataBinding

<asp:Label runat="server" Text='<%# DataBinder.Eval(DataItem.Container, "total", "{0:C"} %>'/>


otherwise use string.format the same way.
 
Share this answer
 
Comments
Maciej Los 24-May-12 12:14pm    
My 5!
ythisbug 24-May-12 12:18pm    
here total contains??column name??
SQL
alter PROCEDURE usp_SumCash
@Sum int Output


AS
BEGIN
set  @Sum=(Select SUM(cCash) from tblCash)
if (len(@Sum)=0) set @Sum=0

SET NOCOUNT ON;


END

remove this line
where cCash=@Sum -- it is out put parameter
 
Share this answer
 
v2

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