using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DataUpdate06
{
public partial class Form1 : Form
{
OleDbConnection thisConnection;
OleDbDataAdapter thisAdapter;
DataSet thisDataSet;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
thisConnection =
new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\360\Programs_managedVCSharp\rnrbooks.mdb");
thisConnection.Open();
thisAdapter =
new OleDbDataAdapter("SELECT ISBN, Title, Author FROM Books", thisConnection);
thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "Books");
foreach (DataRow theRow in thisDataSet.Tables["Books"].Rows)
{
displayTextBox.Text +=
theRow["ISBN"] +"\t" + theRow["Title"] + "\t" + theRow["Author"] + "\r\n";
}
}

private void buttonChange_Click(object sender, EventArgs e)
{
OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter);
thisAdapter.Fill(thisDataSet, "Books");
int rownum = int.Parse(recnumTextBox.Text);
thisDataSet.Tables["Books"].Rows[rownum]["ISBN"] = newISBNTextBox.Text;
thisDataSet.Tables["Books"].Rows[rownum]["Title"] = newtitleTextBox.Text;
thisDataSet.Tables["Books"].Rows[rownum]["Author"] = newAuthorTextBox.Text;
thisAdapter.Update(thisDataSet, "Books"); //Without CommandBuilder this would fail
labelChangeMade.Text = "The change was made";
thisConnection.Close();
}
}
}