Hi,
I am designing a login page using C#.net as front end and MS ACCESS 2007 as back end. During runtime I get an error "ExecuteReader: Connection property has not been initialized." following is my code. Please help me.
I am designing a login page using C#.net as front end and MS ACCESS 2007 as back end. During runtime I get an error "ExecuteReader: Connection property has not been initialized." following is my code. Please help me.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Odbc;
namespace Accounts
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form2 a = new Form2();
a.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
string conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\register.accdb";
OleDbConnection con2 = new OleDbConnection(conStr);
con2.Open();
OleDbCommand cmd2 = new OleDbCommand("Select Table_name from register where User_name='"+textBox1.Text+"' and Password='"+textBox2.Text+"'");
// cmd2.ExecuteNonQuery();
OleDbDataReader dr = cmd2.ExecuteReader();
if(dr.Read())
{
if (textBox1.Text == dr["User_name"].ToString() && textBox2.Text == dr["Password"].ToString())
{
MessageBox.Show("login successfull");
}
else
{
MessageBox.Show("invalid password and id");
}
}
con2.Close();
}
}
}