Hi all,
when i execute it gives me this exception.
I am trying but i coudnt slove.
Plz help me.
InvalidOperationException
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
it points to this line -> "int executed = com.ExecuteNonQuery();"
this is my code:
try
{
DateTime dt = DateTime.Now;
CN = new SqlConnection(concString);
CN.Open();
String qry = "update BookMaster set Cat_code=" + int.Parse(Cat) + " Title='" + title + "' Publisher='" + Pub + "' No_Of_Pages=" + int.Parse(Page) + " No_Of_Cops=" + int.Parse(Copes) + " Date='" + dt.ToString() + "' price=" + int.Parse(Price) + " year_of_pub=" + int.Parse(Year) + " where Book_ID='" + GetBookId() + "'";
SqlCommand com = new SqlCommand(qry, CN);
int executed = com.ExecuteNonQuery();
if (executed == 1)
{
MessageBox.Show("Successfully inserted to the database");
}
else
{
MessageBox.Show("Insertion failed");
}
}
catch (SqlException ex)
{
MessageBox.Show("A SqlException. You must check the Querry parameteres");
MessageBox.Show(ex.ToString());
}
finally
{
CN.Close();
}