locked
Vb.net; DB(accdb): issues oledb vs sqloledb, updating a table RRS feed

  • Question

  • I am trying to use the following code to update a datadate  accdb DB but I kept getting " An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.  I am usingMicrosoft. ACE.OLEDB. Second issues : How do I include the the update statement to save my  data in the database

    Thanks

     Dim strConn As String              'This declares or creats the connection string
            strConn = "Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Amaechi\Documents\Databases\Humanresouces.accdb"
            Dim myConn As New OleDbConnection(strConn)
            Dim InSertLast As String = "insert into StudentTbl(FirstName,LastName)Values (@FirstName, @LastName)"
            'declare sql Command
            Dim insert As New OleDbCommand(InSertLast, myConn)
            'use the WITH Loop fuction to loop through the data in the text boxes
            With insert.Parameters
                .Add(New OleDbParameter("@FirstName", TxtFirstName.Text.Trim))
                .Add(New OleDbParameter("@LastName", TxtLastName.Text.Trim))
            End With
            ' The Connection to the database
            myConn.Open()
            Dim Affected As Integer = 0
    
            Affected = insert.ExecuteNonQuery() 'excute Query
            If Affected = 1 Then
                MessageBox.Show("Success")
            Else
                MessageBox.Show("Failed")
            End If
    
            myConn.Close()
        End Sub
    
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            'Saving data bofore exit the form 
            Dim MessageString As String
            Dim ResponseDialogResult As DialogResult
            MessageString = "Save Data?"
            ResponseDialogResult = MessageBox.Show("Do you want to save Data?", "Warning", MessageBoxButtons.YesNo)
            If ResponseDialogResult = Windows.Forms.DialogResult.Yes Then
                ' Update table now
            End If
            Me.Close()
    


    "

    Saturday, February 2, 2013 8:40 AM

Answers

  • I think you posted this in the wrong forum but to answer your question I do not see the provider in the connection string

     strConn = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Amaechi\Documents\Databases\Humanresouces.acc

    Saturday, February 2, 2013 3:14 PM

All replies

  • I think you posted this in the wrong forum but to answer your question I do not see the provider in the connection string

     strConn = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Amaechi\Documents\Databases\Humanresouces.acc

    Saturday, February 2, 2013 3:14 PM
  • Looks like the string got truncated at the end of Ken's example, otherwise he has it correct:

    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Amaechi\Documents\Databases\Humanresouces.accdb"

    http://www.connectionstrings.com/access-2007#ace-oledb-12-0



    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, February 6, 2013 1:03 PM