Israel

Israel

  • 701
  • 1.3k
  • 216.5k

Why sometime this message appear???

Oct 13 2015 9:56 AM
Hi,
I have somethink I need to understand. Why this message appear sometime when I run my program. It doesnt appear allways. But sometime. When Then how can I fix it to evitate because when I comment my connection its works for a while (later its buggs). Even I leave my connection in order or open/close (its works but anytime later its buggs). Thes error message: The connection was not closed. The connection's current state is open. 
 
public Entrada()
{
InitializeComponent();
}
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Visa\App_Data\finance.mdb;Persist Security Info=False");
OleDbCommand comm;
string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Visa\App_Data\finance.mdb;Persist Security Info=False";
 
conn.Open();// the error message point here
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Lancamento where data_recepcao ='" + dtEntrada.Text + "'";
var param1 = new OleDbParameter("@data_recepcao", OleDbType.VarChar);
param1.Value = dtEntrada.Text;
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
dgvLancamento.DataSource = dt;
conn.Close();// the error message point here
 
 

Answers (1)