Aha už to mám. Ak by to niekoho zaujímalo. Tabulka1: Id, Meno, Priezvisko. Pre Id je automatické číslovanie nastavené v MS Access.
Dim Con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB\dbAccess.mdb")
Dim Dad As OleDbDataAdapter
Dim Cmd As OleDbCommand
Dim Dst = New DataSet
Dim Str As String
Try
Str = "insert into Tabulka1 (Meno, Priezvisko) values("
Str += """" & TextBox2.Text.Trim() & """"
Str += ","
Str += """" & TextBox3.Text.Trim() & """"
Str += ")"
Con.Open()
Cmd = New OleDbCommand(Str, Con)
Cmd.ExecuteNonQuery()
Dst.Clear()
Dad = New OleDbDataAdapter("SELECT * FROM Tabulka1 ", Con)
Dad.Fill(Dst, "TicTac")
MsgBox("Zapísané")
Con.Close()
Catch ex As Exception
MessageBox.Show("Nemôže zapísať")
MsgBox(ex.Message & " - " & ex.Source)
Con.Close()
End Try
|