string constr = ConfigurationManager.ConnectionStrings["SampleAppConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "delete FROM [DetailTable] where ID = '" + prodID +"'";
cmd.Connection = con;
cmd.ExecuteNonQuery();
}
}
ERROR :
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
while I am Using statement needs to write connection open () and close()??
which is the better why to use the using statement?