Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
update tbl_OpdClaim set totalamt=(@totalamt ),Balance =(@Balance ) where userid='" + txtUserId.Text + "'";


i got this error Error: 'Must declare the scalar variable i am not getting what's wrong plz help me
Posted
Updated 20-May-11 19:29pm
v2

When you create the command, you must add the parameters with the values to it before it can execute:

SqlCommand com = new SqlCommand("UPDATE tbl_OpdClaim SET totalamt=(@totalamt ),Balance =(@Balance ) WHERE userid=@ID", con);
com.Paramaters.AddWithValue("@totalamt", myTotalAmount);
com.Paramaters.AddWithValue("@Balance", myNewBalance);
com.Paramaters.AddWithValue("@ID", txtUserId.Text);


Note also that you should parameterize you ID: concatenating strings like that is an invitation to an accidental or deliberate SQL Injection attack.
 
Share this answer
 
You have not passed the two parameter @totalamt,@Balance

for that you need to do some work as below.


C#
SqlCommand cmd = new SqlCommand("update tbl_OpdClaim set totalamt=(@totalamt ),Balance =(@Balance ) where userid='" + txtUserId.Text + "'", con);
        cmd.Parameters.AddWithValue("@totalamt", amountvalue);
        cmd.Parameters.AddWithValue("@Balance", balance);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
 
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