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;
namespace UsingAccess
{
public partial class namesForm : Form
System.Data.OleDb.OleDbConnection con;
DataSet ds1;
System.Data.OleDb.OleDbDataAdapter da;
public namesForm()
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) /* loads the 1st record in school.mdb to the form */
con = new System.Data.OleDb.OleDbConnection();
ds1 = new DataSet();
con.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/school.mdb";
string sql = "SELECT * From [Names]";
da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
con.Open();
da.Fill(ds1, "Names");
NavigateRecords();
con.Close();
con.Dispose();
private void NavigateRecords()
DataRow dRow = ds1.Tables["Names"].Rows[0];
firstNameTextBox.Text = dRow.ItemArray.GetValue(1).ToString();
lastNameTextBox.Text = dRow.ItemArray.GetValue(2).ToString();
address1TextBox.Text = dRow.ItemArray.GetValue(3).ToString();
address2TextBox.Text = dRow.ItemArray.GetValue(4).ToString();
phoneNoTextBox.Text = dRow.ItemArray.GetValue(5).ToString();
private void btnSave_Click(object sender, EventArgs e)
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/school.mdb";
System.Data.OleDb.OleDbCommandBuilder cb;
cb = new System.Data.OleDb.OleDbCommandBuilder(da);
DataRow dRow = ds1.Tables["Names"].NewRow();
dRow[0] = IDNoTextBox.Text;
dRow[1] = firstNameTextBox.Text;
dRow[2] = lastNameTextBox.Text;
dRow[3] = address1TextBox.Text;
dRow[4] = address2TextBox.Text;
dRow[5] = phoneNoTextBox.Text;
dRow[6] = yearNoTextBox.Text;
ds1.Tables["Names"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
da.Update(ds1, "Names");
MessageBox.Show("Entry Added");