Using Using Using Using Using Using Namespace: Class
Using Using Using Using Using Using Namespace: Class
Forms;
//main form
namespace userdetail { public partial class MainForm : Form { OleDbConnection con; DataSet ds; public MainForm() { InitializeComponent(); } void MainFormLoad(object sender, EventArgs e) { string constr = "provider= Microsoft.ACE.OLEDB.12.0; Data Source=E:\\ravi.accdb; "; con = new OleDbConnection(constr); con.Open(); OleDbDataAdapter da = new OleDbDataAdapter("select * from suhag", con); ds = new DataSet(); da.Fill(ds); } void Button2Click(object sender, EventArgs e) { OleDbCommand cmd = new OleDbCommand("select * from suhag where [Id]='"+textBox1.Text+"' and [Password]='"+textBox3.Text+"'", con); OleDbDataReader dr = cmd.ExecuteReader(); if(dr.Read() == true) { MessageBox.Show("Login Successful"); textBox1.Text=""; textBox2.Text=""; textBox3.Text=""; } else { MessageBox.Show("Invalid user-name or password"); } }
void Button1Click(object sender, EventArgs e) { Form1 secondForm = new Form1(); secondForm.Show(); } } } /////Form 1 using System; using System.Drawing; using System.Windows.Forms; using System.Data.OleDb; using System.Data; namespace userdetail { public partial class Form1 : Form {OleDbConnection con; public Form1() { InitializeComponent(); } void Form1Load(object sender, EventArgs e) { string str = "provider= Microsoft.ACE.OLEDB.12.0; Data Source=E:\\ravi.accdb; "; con=new OleDbConnection(str); con.Open(); OleDbDataAdapter da=new OleDbDataAdapter("Select * from suhag",con); DataSet ds=new DataSet(); da.Fill(ds); } void Button1Click(object sender, EventArgs e) { if (textBox1.Text=="") { MessageBox.Show("enter the data"); } else{ OleDbCommand cmd =new OleDbCommand("insert into suhag values('"+textBox1.Text+"','"+textBox2.Text+"',"+textBox3.Text+",'"+textBox4.Text+"')",con); cmd.ExecuteNonQuery();
MessageBox.Show("Account has been created"); textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; } } } }