Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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?
    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:\Users\Compaq\Documents\Koen\VBproject\LoginTest.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:\Users\Compaq\Documents\Koen\VBproject\LoginTest.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 Class
    I 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!
    Last edited by VIPStephan; 09-02-2013 at 04:09 PM. Reason: corrected code BB tags

  • #2
    New Coder
    Join Date
    Apr 2013
    Posts
    38
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Smile

    I think the table in the database doesn't exist. try these changes below.

    Code:
     ds.Tables("Gebruikers").Rows.Add(dsNewRow)
                    Dim command As OleDb.OleDbCommand = New OleDb.OleDbCommand
                    command.CommandText = "CREATE TABLE Gebruikers"
                    command.ExecuteNonQuery()
                    da.Update(ds, "Gebruikers")
    We offer Website Development with 5 years expertise in Joomla Development and ecommerce development.

  • #3
    Regular Coder
    Join Date
    May 2012
    Location
    USA
    Posts
    102
    Thanks
    0
    Thanked 7 Times in 7 Posts
    You can refer the book by "Apress" as it is one of the best book for learning Asp.Net.

  • #4
    Regular Coder
    Join Date
    May 2012
    Location
    USA
    Posts
    102
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Rather than using Access 2007 try to use MS Sql Server 2010 as it would be a lot easier to bind data using it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •