link

I have a small application, i can save the first record, no issues, but i am continuing on the same form and enter the next record, gives me error "The transaction is either not associated with the current connection or has been completed". But if i close and open the form i can enter the next record. I cannot enter the data continously. I am attaching the code i am using for saving the data. Please help me.

###############################################################################################
this.BindingContext[dsSupplier, "m_supplier"].EndCurrentEdit();
if (myCon.State != ConnectionState.Open)
myCon = Program.ConnectToDB(myCon);

int lisupCode = 0;

if (ic_TransMode == 'N')
{
SqlCommand cmd = new SqlCommand("select isnull(max(n_sup_code),0) + 1
from m_supplier", myCon);
SqlDataReader dr;

dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
lisupCode = System.Convert.ToInt32(dr.GetValue(0).ToString());
}
}
dr.Close();
cmd.Dispose();
dsSupplier.Tables["m_supplier"].Rows[0]["n_sup_code"] = lisupCode.ToString();
dsSupplier.Tables["m_supplier"].Rows[0]["n_co_code"] = Program.g_cocode;
}
else
{
lisupCode = System.Convert.ToInt32(dsSupplier.Tables
["m_supplier"].Rows[0]["n_sup_code"]);
}

SqlCommandBuilder cbComp = new SqlCommandBuilder(daSupplier);
daSupplier.InsertCommand = cbComp.GetInsertCommand();
daSupplier.UpdateCommand = cbComp.GetUpdateCommand();
daSupplier.DeleteCommand = cbComp.GetDeleteCommand();

SqlTransaction myTrans;

myTrans = myCon.BeginTransaction();

daSupplier.InsertCommand.Transaction = myTrans;
daSupplier.UpdateCommand.Transaction = myTrans;
daSupplier.DeleteCommand.Transaction = myTrans;

try
{
daSupplier.Update(dsSupplier, "m_supplier");
dsSupplier.AcceptChanges();
myTrans.Commit();
MessageBox.Show("Data Saved.");
ResetForm();
}
catch (Exception e)
{
myTrans.Rollback();
MessageBox.Show(e.Message);
}


myCon.Close();
###############################################################################################

Please help me.