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();
}
}
}
|