Click here to Skip to main content
15,888,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<sqlconnection con="new" mode="hold"> con.Open();
SqlCommand cmd = new SqlCommand("update tblRegi set Firstname=@Firstname,Lastname=@Lastname,Username=@Username,Password=@Password,Repassword=@Repassword,Gender=@Gender,Hobbies=@Hobbies,Country=@Country,State=@State,City=@City,Secrtyque=@Secrtyque,Secrtyans=@Secrtyans where id=@id", con);
cmd.Parameters.AddWithValue("@Firstname", TxtFirstname.Text);
cmd.Parameters.AddWithValue("@Lastname", TxtLastname.Text);
cmd.Parameters.AddWithValue("@Username", TxtUsername.Text);
cmd.Parameters.AddWithValue("@Password", TxtPasswword.Text);
cmd.Parameters.AddWithValue("@Repassword", TxtRePassword.Text);
cmd.Parameters.AddWithValue("@Gender", RbtnGender.SelectedValue);
cmd.Parameters.AddWithValue("@Hobbies", ChbxHobbies.SelectedValue);
cmd.Parameters.AddWithValue("@Country", DrpCountry.SelectedValue);
cmd.Parameters.AddWithValue("@State", DrpState.SelectedValue);
cmd.Parameters.AddWithValue("@City", DrpCity.SelectedValue);
cmd.Parameters.AddWithValue("@Secrtyque", DrpScQue.SelectedValue);
cmd.Parameters.AddWithValue("@Secrtyans", TxtScAns.Text);
cmd.Parameters.AddWithValue("@id",Label1.Text);
cmd.ExecuteNonQuery();
con.Close();

What I have tried:

what i do that solve this error
Posted
Updated 16-Mar-16 22:09pm

1 solution

Just like C# has strict typing and you can't do this:
C#
int id = "label";

..your database as strict typing as well and you can't assign a string (in this case apparently containing "label") to a column with a type of int or compare them directly.

Most probably it's this line:
C#
cmd.Parameters.AddWithValue("@id",Label1.Text);
Theoretically you should use Int32.TryParse(..)[^] to parse the string into an integer. But first you need to take care that the text of the label actually shows a valid integer and not "label" otherwise .TryParse(..) will fail.

Other than that: It appears you're storing passwords as plain text in your database. You might want to give these a read:
Beginners guide to a secure way of storing passwords[^]
Secure Password Authentication Explained Simply[^]
 
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