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

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

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
We take content rights seriously. If you suspect this is your content, claim it here.
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy