Dennis,
My believe was not true, however the rest is. Therefore I have not to
believe anymore I know.
You can try this sample it needs a button and a datagrid on a form and a
reference to COM adox ext 2.x for dll and security
\\\ When you have tested it than change the part where I have told that add
your adding of the key
Private da As New OleDb.OleDbDataAdapter
Private Sub Form7_Load(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\test1\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=c:\test1\db1.mdb")
'To make tables we use Adonet
Dim conn As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
" Data Source=C:\test1\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE Dennis ( " & _
"Col1 int identity ," & _
"Col2 NVarchar(50)," & _
"CONSTRAINT [pk_Col1] PRIMARY KEY (Col1)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
Dim dt As New DataTable
Dim selectstring As String = "Select * from Dennis"
da = New OleDb.OleDbDataAdapter(selectstring, conn)
da.FillSchema(dt, SchemaType.Mapped)
dt.Columns(0).AutoIncrementSeed = -1
dt.Columns(0).AutoIncrementStep = -1
'Populate the Columns
Dim irand As New Random(123)
Dim k As Integer
For i As Integer = 1 To 25
k = irand.Next
Dim newrow As DataRow = dt.NewRow
newrow("col1") = CType(k, Int32)
'delete this row to see it with the autoseed
newrow("col2") = "ABCD"
dt.Rows.Add(newrow)
Next i
DataGrid1.DataSource = dt
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim cmb As New OleDb.OleDbCommandBuilder(da)
Dim dt As DataTable = DirectCast(DataGrid1.DataSource, DataTable)
da.Update(dt)
dt.Clear()
da.Fill(dt)
DataGrid1.DataSource = dt
End Sub
///
I hope this helps?
Cor