How to insert data into table "users" with VB.net 2010 into access 2007 database?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I would like to know what the VB.NET code should be on how to insert data via VB.net express 2010 form fields into an access 2007 database.
I get a syntax error (near to the da.update) when I use the following code.
Can anyone help me and give me the correct code?Public Class Registreren

Dim da As OleDb.OleDbDataAdapter
Dim ds As New DataSet

Dim con As New OleDb.OleDbConnection
Dim sql As String

Dim dbProvider As String
Dim dbSource As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegisterButton.Click
On Error GoTo Fout
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow

If GebruikersnaamTextBox.Text = "" Or WachtwoordTextBox.Text = "" Or EmailTextBox.Text = "" Then
MsgBox("Alle velden zijn verplicht!")
Else
If EmailTextBox.Text Like "*@*.*" Then

dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source = C:UsersCompaqDocumentsKoenVBprojectLoginTest.accdb"

con.ConnectionString = dbProvider & dbSource

con.Open()

dsNewRow = ds.Tables("Gebruikers").NewRow()

dsNewRow.Item("Gebruikersnaam") = GebruikersnaamTextBox.Text
dsNewRow.Item("Wachtwoord") = WachtwoordTextBox.Text
dsNewRow.Item("E-mail") = EmailTextBox.Text
dsNewRow.Item("Beheerder") = False

ds.Tables("Gebruikers").Rows.Add(dsNewRow)
da.Update(ds, "Gebruikers")

Me.Close()
Else
MsgBox("Ongeldig e-mail adres!")
End If
End If
Exit Sub

Fout:
MsgBox("Fout " & Err.Number & vbCrLf & Err.Description)
End Sub

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source = C:UsersCompaqDocumentsKoenVBprojectLoginTest.accdb"

con.ConnectionString = dbProvider & dbSource

con.Open()

sql = "SELECT * FROM Gebruikers"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Gebruikers")

con.Close()

End Sub
End ClassI cannot find the correct documentation for programming VB.net projects in VB expres 2010 using database inserts, updates, deletes etc..
Does anyone know a good course book or tutorial which mainly deals with the VB programming and databases (in this case access databases)?

Thanks in advance!

View the full article
 
Back
Top