Here is my following code:
string csr = "connection string";
string add = "Insert INTO table (Column1,Column2,Column3) Values (@Column1,@Column2,@Column3)";
using(SqlConnection connect = new SqlConnection(csr))
{
using ( SqlCommand command = new SqlCommand(add,connect))
{
command.Parameters.AddWithValue("Column1",textbox1.text");
//and so on
connect.Open();
command.ExecuteReader();
connect.Close();
}
}
I can see the data added in the gridview but when I check the table data in c# is empty, no value added. what’s wrong?
You shouldn’t have the
connect.Close();, theusingstatement will take care of that for you.