Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if (Module1.action == "Add")
{



SqlCommand com = new SqlCommand();
com.CommandText = "insert into Customer values(@CNo,@CName,@Date,@CAddress,@Contact_No,@Deleted)";
com.Parameters.AddWithValue("@CNo", txtcustno.Text);
com.Parameters.AddWithValue("@CName", txtcustname.Text);
com.Parameters.AddWithValue("@Date", txtdate.Text);
com.Parameters.AddWithValue("@CAddress", txtcustaddress.Text);
com.Parameters.AddWithValue("@Contact_No", txtcontact.Text);

//com.Parameters.AddWithValue("@UNo", Module1.st);
com.Parameters.AddWithValue("@Deleted", "0");
com.Connection = Module1.con;
try
{
Module1.con.Open();
com.ExecuteNonQuery();



// Module1.con.Open();
//com.ExecuteNonQuery();
// MessageBox.Show("Record saved");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Module1.con.Close();
fill();
binding();
Button(!Module1.b);

Locked(Module1.d);
MessageBox.Show("Record saved");
// Clientid = txtcustno.Text
return;
}
else if (Module1.action == "Update")
Posted
Comments
[no name] 11-Apr-14 6:49am    
Wow... an unformatted wall of code without an explanation.
BulletVictim 11-Apr-14 7:05am    
Finally
{
if(Module1.con.State > 0)
{
Module1.Con.Close()
}
}

Next time try to format your code correctly so that we can read it easier, and try to give some kind of explanation as to what your problem is. And what is happening when you get the problem
ZurdoDev 11-Apr-14 8:42am    
The error is very clear. Do you have a question?

1 solution

once the connection is Open make sure its is closed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900