Using MS Access with C#.Net
This video demonstrate the connection establishment with the MS Access database with the C#.Net
Table Structure
Source Code :
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 DatabaseConnection
{
public partial class Form1 : Form
{
OleDbConnection vcon=new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\admin\My Documents\Database2.accdb");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
vcon.Open();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string vsql = string.Format("insert into student_details values({0},'{1}',{2},'{3}')", int.Parse( textBox1.Text), textBox2.Text, int.Parse(textBox3.Text), textBox4.Text);
OleDbCommand vcom = new OleDbCommand(vsql, vcon);
vcom.ExecuteNonQuery();
MessageBox.Show("Data stored successfully");
vcom.Dispose();
}
private void button4_Click(object sender, EventArgs e)
{
string vsql = "select * from student_details ";
OleDbCommand vcom = new OleDbCommand(vsql, vcon);
DataSet vds = new DataSet();
OleDbDataAdapter vda = new OleDbDataAdapter(vcom);
vda.Fill(vds, "res");
dataGridView1.DataSource = vds.Tables["res"];
vda.Dispose();
vcom.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text="";
textBox4.Text = "";
textBox3.Text = "";
}
}
}
Direct Link : Click here
Comments