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);
}
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);
}
IsraelPosted Nov 12, 2016, 12:52 PM
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);
}
finally
{
conn.Close();
}
Tapan PatelPosted Nov 11, 2016, 9:13 AM
Harshal ThakrePosted Nov 11, 2016, 8:37 AM