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 alhuda_marksheet
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
connection c = new connection();
string connectionString = null;
OleDbConnection connection;
OleDbDataAdapter oledbAdapter;
DataSet ds = new DataSet();
string sql = null;
int i = 0;
int a;
private void button1_Click(object sender, EventArgs e)
{
// connection= new OleDbConnection();
//connection.ConnectionString = c.con();
connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\lucknowacademy.accdb";
connection = new OleDbConnection(connectionString);
try
{
sql = "select username,password,type from admin where type='"+comboBox1.Text+"'";
connection.Open();
oledbAdapter = new OleDbDataAdapter(sql, connection);
oledbAdapter.Fill(ds);
oledbAdapter.Dispose();
connection.Close();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
if ((ds.Tables[0].Rows[i].ItemArray[0]).ToString() == textBox1.Text && (ds.Tables[0].Rows[i].ItemArray[1]).ToString() == textBox2.Text)
{
MDIParent1 obj = new MDIParent1();
if ((ds.Tables[0].Rows[i].ItemArray[2]).ToString() == "Admin")
{
obj.Show();
a++;
this.Hide();
break;
}
else
if ((ds.Tables[0].Rows[i].ItemArray[2]).ToString() == "User")
{
MDIParentuser obj1 = new MDIParentuser();
obj1.Show();
a++;
this.Hide();
break;
}
}
}
if (a == 0)
{
MessageBox.Show("Wrong User name and Password");
}
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! " + ex.Message);
}
}
}
}
No comments:
Post a Comment