Error ,Invalid operationException was unhandled by user code,Sql

Posted by Raja_89 under Sql Server on 6/3/2013 | Points: 10 | Views : 659 | Status : [Member] | Replies : 1
Hai Techie

When i try to execute following code it shows an error called

Code:
string updatesql = "update Stu_Detailstable set St_Second ='" + AmountpaidText.Text + "' , St_sinsbillno='" + BillnoText.Text + "' , SIpaiddate='" + PaidonText.Text + "',Chequeno='" + CheqnoTextBox.Text + "'where St_phone= '" + SearchcontactnoText.Text + "'";

SqlCommand command = new SqlCommand(updatesql, con);
FinSqldataSource.UpdateCommand = updatesql;
FinSqldataSource.Update();
con.Open();

int result =command.ExecuteNonQuery();
if (result == 1)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Transaction Sucessfull ');", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Transaction Sucessfull');", true);
}



Invalid operationException was unhandled by user code

The connection was not closed. The connection's current state is open.




What does it means ?




Responses

Posted by: Niladri.Biswas on: 6/3/2013 [Member] Platinum | Points: 25

Up
0
Down
Use Using block.
e.g.

using (DbConnection conn = new DbConnection())
{
// do stuff with database
}

Best Regards,
Niladri Biswas

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response