Israel

Israel

  • 701
  • 1.3k
  • 215.8k

Deleting only for the first time (not the second time once)

Nov 11 2016 7:40 AM
Hi!
 
I wrote these to delete one row from database. Curiously, after to delete one and if I need to delete another I receive this message and don't want to delete another without restart my program. After to restart then Its can delete.
Error Message: The connection was not closed. The connection's current state is open
 
 String strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\LunaFoods\LunaFoods\App_Data\office.mdb;Persist Security Info=False";
string query = "delete from cadastramento where nprocesso='" + lblnProcessoCadastramento.Text + "';";
OleDbConnection conDatabase = new OleDbConnection(strConnection);
OleDbCommand cmdDatabase = new OleDbCommand(query, conn);
OleDbDataReader myReader;
try
{
conn.Open();
myReader = cmdDatabase.ExecuteReader();
MessageBox.Show("Dados excluidos com exito. Obrigado!");
while (myReader.Read())
{
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

Answers (3)