Reputation: 267
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?
Upvotes: 0
Views: 125
Reputation: 8098
You shouldn't have the connect.Close();
, the using
statement will take care of that for you.
Upvotes: 1
Reputation: 5004
command.Parameters.AddWithValue("Column1",textbox1.text")
should be
command.Parameters.AddWithValue("Column1",textbox1.text)
Set a breakpoint and ensure your connectionstring was properly set, textbox has a value, etc...
Upvotes: 0