0% found this document useful (0 votes)
35 views3 pages

Using Using Using Using Using Using Namespace: Class

This document contains code for a C# Windows Forms application that allows users to log in and create new accounts in an Access database. The MainForm class handles logging in by querying the database and checking the username and password. If credentials match, it displays a success message. Otherwise, it shows an error. The Form1 class allows adding new user records. It opens a connection to the Access file and inserts textbox values into the database table on a button click. Validation checks for empty fields and displays messages.

Uploaded by

ravisuhag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Using Using Using Using Using Using Namespace: Class

This document contains code for a C# Windows Forms application that allows users to log in and create new accounts in an Access database. The MainForm class handles logging in by querying the database and checking the username and password. If credentials match, it displays a success message. Otherwise, it shows an error. The Form1 class allows adding new user records. It opens a connection to the Access file and inserts textbox values into the database table on a button click. Validation checks for empty fields and displays messages.

Uploaded by

ravisuhag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q 18 using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Windows.

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 = ""; } } } }

You might also like