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; namespace WindowsFormsApplication34 { public partial class Form1 : Form { public OleDbConnection con = new OleDbConnection(); public Form1() { InitializeComponent(); string strcon = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Users\\Persian\\Desktop\\a.accdb "; con = new OleDbConnection(strcon); try { con.Open(); } catch (OleDbException e) { MessageBox.Show("Access Error"); MessageBox.Show("Error code= " + e.ErrorCode); MessageBox.Show("Error Message=" + e.Message); } catch (InvalidOperationException e) { MessageBox.Show("Invalid message"+ e.Message); } if (con.State != ConnectionState.Open) { MessageBox.Show("Database connection is failed"); Application.Exit(); } } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string cmdstring = "SELECT * FROM log"; cmdstring += "WHERE (user=@p) AND (pass=@q)"; OleDbDataAdapter logindataadapter = new OleDbDataAdapter(); DataTable accdatatable = new DataTable(); OleDbCommand acccommand = new OleDbCommand(); Form1 a = new Form1(); acccommand.Connection = con; acccommand.CommandType = CommandType.Text; acccommand.CommandText = cmdstring; acccommand.Parameters.Add("@p",OleDbType.Char).Value = textBox1.Text; acccommand.Parameters.Add("@q", OleDbType.Char).Value = textBox2.Text; logindataadapter.SelectCommand = acccommand; logindataadapter.Fill(accdatatable); if (accdatatable.Rows.Count > 0) { MessageBox.Show("Login susseful"); a.Show(); this.Hide(); } else MessageBox.Show("No Matched username/password found"); accdatatable.Dispose(); acccommand.Dispose(); logindataadapter.Dispose(); } } }
logindataadapter.Fill(accdatatable);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)