Must Declear Scalar Variable in Asp.Net Problem
This problem is very common while inserting value in database of SQL. The reason behind this is that:
1. You do not declare your SQL variable in parameters like this
SqlCommand cmd= New SqlCommand(" insert into table name (Name, RollNo) values(@Name, @ RollNo",Con);
cmd.Parameters.AddwithValues("Name", TextBox1.Text);
cmd.Parameters.AddwithValues("RollNo", TextBox2.Text);
cmd.ExecuteNonQuery();
here you should include "@Name" and "@RollNo" with parameters
2. Second which I got is that we write cmd.ExecuteNonQuery(); above the parameter like this
SqlCommand cmd= New SqlCommand(" insert into table name (Name, RollNo) values(@Name, @ RollNo",Con);
cmd.ExecuteNonQuery();
cmd.Parameters.AddwithValues("Name", TextBox1.Text);
cmd.Parameters.AddwithValues("RollNo", TextBox2.Text);
This also shows Scalar variable problem.
I hope this will help you a lot.
thank you
1. You do not declare your SQL variable in parameters like this
SqlCommand cmd= New SqlCommand(" insert into table name (Name, RollNo) values(@Name, @ RollNo",Con);
cmd.Parameters.AddwithValues("Name", TextBox1.Text);
cmd.Parameters.AddwithValues("RollNo", TextBox2.Text);
cmd.ExecuteNonQuery();
here you should include "@Name" and "@RollNo" with parameters
2. Second which I got is that we write cmd.ExecuteNonQuery(); above the parameter like this
SqlCommand cmd= New SqlCommand(" insert into table name (Name, RollNo) values(@Name, @ RollNo",Con);
cmd.ExecuteNonQuery();
cmd.Parameters.AddwithValues("Name", TextBox1.Text);
cmd.Parameters.AddwithValues("RollNo", TextBox2.Text);
This also shows Scalar variable problem.
I hope this will help you a lot.
thank you
Comments
Post a Comment