db

string dbconnection = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ @"data source =BookCSharp.accdb";

prepares a database connection string

string dbcommand = "Select BookKey, Title, Pages from Books;";
OleDbConnection conn = new OleDbConnection(dbconnection);
OleDbCommand comm = new OleDbCommand(dbcommand, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);

Establish the connection and the adaptor

OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);

Generate commands automatically

DataRow newRow = ds.Table[0]. NewRow();
newRow["BookKey"] = txtBookID.Text;
newRow["Title"] = txtTitle.Text;
newRow["Pages"] = txtPages.Text;

define a new record and place it into a new DataRow

ds.Tables[0].Rows.Add(newRow);

add the new DataRow to DataTable

DataSet dataSetChanges = ds.GetChanges();
adapter.Update(dataSetChanges);

update DB

ds.AcceptChanges();

accept changes

string deletedRowBookkey = ds.Tables[0].Rows[ lstDisplayBooks.SelectedIndex].Field<String>("BookKey");
adapter.DeleteCommand = new OleDbCommand(
"DELETE FROM Books WHERE BookKey = '"
+ deletedRowBookkey + "';", conn);

//Prepare the delete command

string dbconnection = "Provider=Microsoft.ACE.OLEDB.12.0;" + @"data source =BookCSharp.accdb";
string dbcommand = "Select BookKey, Title, Pages from Books;";
OleDbConnection conn = new OleDbConnection(dbconnection);
OleDbCommand comm = new OleDbCommand(

//Establish the connection and the adaptor

adapter.Update(ds);

//update DB accordingly

//make change in listBox accordingly

listBox.Items.RemoveAt(dataBox.SelectedIndex);

adapter.InsertCommand = new OleDbCommand(
"insert into Books values (BookKey = '"
+ txtBookID.Text + "', '" + txtTitle.Text + "', '" + txtPages.Text + "')", conn);

//Prepare the insert command

DataRow newRow = dt. NewRow();
newRow["BookID"] = txtBookID.Text;
newRow["Title"] = txtTitle.Text;
newRow["Pages"] = txtPages.Text;

//define a new record and place it into a new DataRow

DataTable inventoryTable = new DataTable("Inventory");

//create a new table

DataColumn carIdColumn = new DataColumn();
carIdColumn.DataType = Type.GetType("System.Int32");
carIdColumn.ColumnName = "CarID";
carIdColumn.AllowDBNull = false;
carIdColumn.Unique = true;
carIdColumn.AutoIncrement = true;
carIdColumn.AutoIncrementSeed =

//create CarID column and add to inventoryTable

DataColumn[] PK = new DataColumn[1];
PK[0] = inventoryTable.Columns["CarID"];
inventoryTable.PrimaryKey = PK;

//set primary key that is CarId column

DataRow newRow;
newRow = inventoryTable.NewRow();
newRow["Make"] = "BMW";
newRow["Colour"] = "Orange";
newRow["PetName"] = "Tiger";
inventoryTable.Rows.Add(newRow);
newRow = inventoryTable.NewRow();
newRow["Make"] = "Ford";
newRow["Colour"] = "Black";
new

//add records to the table