>>Imports System >>Imports System.Data >>Imports System.Data.OleDb >>Imports Microsoft.VisualBasic >> >>Public class Sample >> >> Shared nwindConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _ >> "Data Source=c:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;") >> >> Public Shared Sub Main() >> >> ' Use the DataAdapter to fill and update the DataSet. >> Dim catDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryID", nwindConn) >> >> catDA.InsertCommand = New OleDbCommand("INSERT INTO Categories (CategoryName) Values(?)", nwindConn) >> catDA.InsertCommand.CommandType = CommandType.Text >> >> catDA.InsertCommand.Parameters.Add("@CategoryName", OleDbType.Char, 15, "CategoryName") >> >> nwindConn.Open() >> >> ' Fill the DataSet. >> Dim catDS As DataSet = New DataSet >> catDA.Fill(catDS, "Categories") >> >> ' Add a new row. >> Dim newRow As DataRow = catDS.Tables("Categories").NewRow() >> newRow("CategoryName") = "New Category" >> catDS.Tables("Categories").Rows.Add(newRow) >> >> ' Include an event to fill in the Autonumber value. >> AddHandler catDA.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated) >> >> ' Update the DataSet. >> catDA.Update(catDS, "Categories") >> >> nwindConn.Close() >> End Sub >> >> Private Shared Sub OnRowUpdated(sender As Object, args As OleDbRowUpdatedEventArgs) >> ' Include a variable and a command to retrieve the identity value from the Access database. >> Dim newID As Integer = 0 >> Dim idCMD As OleDbCommand = New OleDbCommand("SELECT @@IDENTITY", nwindConn) >> >> If args.StatementType = StatementType.Insert >> ' Retrieve the identity value and store it in the CategoryID column. >> newID = CInt(idCMD.ExecuteScalar()) >> args.Row("CategoryID") = newID >> args.Row.AcceptChanges() >> End If >> End Sub >>End Class >>>>