Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Accessing Database Using ADO .NET - EXp 8

The document defines a Windows form application that connects to an Access database and allows the user to view, add, and search for records in a database table. It opens a connection to an Access database, displays all records in a data grid on button click, allows adding a new record on another button click, and allows searching for a record by ID on a third button click. All database operations use OleDb classes to execute queries and commands against the database.

Uploaded by

abdulkalam5026
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Accessing Database Using ADO .NET - EXp 8

The document defines a Windows form application that connects to an Access database and allows the user to view, add, and search for records in a database table. It opens a connection to an Access database, displays all records in a data grid on button click, allows adding a new record on another button click, and allows searching for a record by ID on a third button click. All database operations use OleDb classes to execute queries and commands against the database.

Uploaded by

abdulkalam5026
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

using System.

Data;
using System.Data.OleDb;
namespace WinFormsApp2
{
public partial class Form1 : Form
{
OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\data.accdb");
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
string s1 = "select * from [t1]";
OleDbCommand vcomm = new OleDbCommand(s1, vcon);
DataSet vds = new DataSet();
OleDbDataAdapter vda = new OleDbDataAdapter(vcomm);
vda.Fill(vds, "res");
dataGridView1.DataSource = vds.Tables["res"];
vda.Dispose();
vcomm.Dispose();

private void Form1_Load(object sender, EventArgs e)


{
vcon.Open();
}

private void button2_Click(object sender, EventArgs e)


{
string vsql = string.Format("insert into [t1] values('{0}','{1}')", textBox1.Text, textBox2.Text);
OleDbCommand vcomm = new OleDbCommand(vsql, vcon);
vcomm.ExecuteNonQuery();
MessageBox.Show("Added successful");
vcomm.Dispose();

private void button3_Click(object sender, EventArgs e)


{
string s2 = string.Format("select * from [t1] where [id]={0}", textBox3.Text);
//string s2 = "select * from Order where Roll_No='1010'";
OleDbCommand vcom = new OleDbCommand(s2, vcon);
DataSet vd = new DataSet();
OleDbDataAdapter vdap = new OleDbDataAdapter(vcom);
vdap.Fill(vd, "res");
dataGridView2.DataSource = vd.Tables["res"];
vdap.Dispose();
vcom.Dispose();

private void label1_Click(object sender, EventArgs e)


{

}
}
}

You might also like