public partial class Form1: Form
{
OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
con.ConnectionString = "Provider= Microsoft.ACE.OLEDB.12.0;Data
Source= Assignment.accdb";
con.Open();
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "select * from SignUp where Username = '" +
textBox1.Text + "' and Password= '" +
textBox2.Text + "'";
OleDbDataReader dr = cmd.ExecuteReader();
int count = 0;
while (dr.Read())
{
count++;
}
if (count ==1 )
{
MainMenu menu = new MainMenu();
menu.Show();
this.Close();
}
else
{
MessageBox.Show("Incorrect Username or Password");
}
con.Close();
can anyone help me to check my code How to fix this error 'The connection was not closed. The connection's current state is open.'
although I have closed the connection
** the message The connection was not closed. The connection's current state is open.is shown at (con.open(); [private void button1_Click_1])