Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi am getting error while adding records to sql table
my tblCash contains cCash column.decimal(18,4)
protected void btnAdd_Click(object sender, EventArgs e)
    {
        
        txtAmount.Text = "";
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());

        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_Insert_Update_Record";
       
        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();

    }

and here is my sp
alter proc usp_Insert_Update_Record
@status int,
@money decimal (18,4)
as
if(@status=1)
begin
update tblCash set cCash=cCash+@money
end
else if (@status=2)
begin
declare @balanceAmount decimal(18,4)
select @balanceAmount=cCash 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 cCash=cCash-@money
end
end

am getting error like failed to convert parameter value from string to decimal
can any one suggest me how to solve.?

and can any one tel me how to assign value for status..but i din add in my table status..can any one suggest me?

@d4742 i assigned value also but if i assign as convert.todouble(txtAmount.text);its coming error like input string was not in a correct format.
can anybody help?

@Sagar Wasule..i used decimal(18,4) for cCash in my table
please any one help me..
Posted
Updated 7-May-12 22:54pm
v8

first error : u r using @status in your sp but u r not assigning any value to that varible
 
Share this answer
 
second error

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

where is cash????

use Conver.ToDouble(txtAmount.Text) while assigning value.
 
Share this answer
 
Check for the data type used in table for cash column , might be it is varchar or string that is causing some problem
 
Share this answer
 

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