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 


 
 

 
 

Comments

Popular posts from this blog

DTS package conversion in SSIS to use in SQL 2012 and SQL 2016

Infinite Scroll in Asp.Net C# using Javascript without Third party Plugin

Add Custom Tags in Web config file in ASP .Net