Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
string str = "UPDATE EMPDETAILS SET NAME=@name,DEPT=@dept,CITY=@city WHERE chkstatus=@chkstatus AND EMPID=empid";

        cmd = new SqlCommand(str, con);
        cmd.Parameters.AddWithValue("@empid", txtempid.Text);
        cmd.Parameters.AddWithValue("@name", txtname.Text);
        cmd.Parameters.AddWithValue("@dept", txtdept.Text);
        cmd.Parameters.AddWithValue("@city", txtcity.Text);
        cmd.Parameters.AddWithValue("@chkstatus", status.Trim());
        cmd.ExecuteNonQuery();
        GridView1.DataBind();
        lblmsg.Text = "RECORD UPDATE SUCCESSFULLY";
        con.Close();
        btnsubmit.Visible = false;
        btnupd.Visible = true;
        txtempid.ReadOnly = true;
        Binddata()
Posted
Updated 30-Jul-12 3:47am
v2
Comments
I.explore.code 30-Jul-12 9:38am    
so what's your exact problem? Please don't paste code and expect us to guess your problem. Are you getting any errors?
[no name] 30-Jul-12 9:48am    
This is just a code dump, not a question.

However, I can see one simple glitch in your code and so I m putting it in the solution box here. The "empid" in your update statement is not parameterised by the "@" symbol

C#
string str = "UPDATE EMPDETAILS SET NAME=@name,DEPT=@dept,CITY=@city WHERE chkstatus=@chkstatus AND EMPID=@empid";


I am not sure if this is what you wanted but this is atleast one problem that i spotted in your code. For anything else you've got to tell us so.
 
Share this answer
 
Comments
OriginalGriff 30-Jul-12 9:50am    
:thumbsup: Yours didn't show on my PC when I posted mine.
I.explore.code 30-Jul-12 9:58am    
thanks,that's ok! :) stars don't matter more than helping someone out ;) (but yeah, couple of stars are good for creditbility...lol)
Add an '@' character to empid in the main string:
SQL
string str = "UPDATE EMPDETAILS SET NAME=@name,DEPT=@dept,CITY=@city WHERE chkstatus=@chkstatus AND EMPID=empid";
Becomes
SQL
string str = "UPDATE EMPDETAILS SET NAME=@name,DEPT=@dept,CITY=@city WHERE chkstatus=@chkstatus AND EMPID=@empid";


That way it matches the paramater name
 
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