none
Connection to access 2007 from vb 2008

    Question

  • Hi,

    I have used vb before and connected to access databases, using the code:

    dim con as adodb.connection
    dim rst as adodb.recordset

    I am trying to do the same in vb 2008 and it doesnt recognise the adodb.connection or recordset.  I have had a look to see if there is anything that i need to do, but i cant see.  References

    Many thanks
    Thursday, July 30, 2009 10:19 AM

Answers

All replies

  • Proabably your connectionstring but I am not sure if it is working for adodb too.

    http://www.connectionstrings.com/access-2007

    Success
    Cor
    Thursday, July 30, 2009 10:40 AM
  • Hi

    I have the connection strings.  It is when i declare the recordset and connection i get 'Type Recordset is not defined'  do i need to switch the ADODB on, like the references?

    thanks

    nathan
    Thursday, July 30, 2009 10:46 AM
  • You can still use ADO but why not use ADO.NET instead? You can find a project example at the below link:

    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1991&lngWId=10


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, July 30, 2009 12:31 PM
  • Nathan,

    Sorry I should have seen this earlier, have you set using Project->References a reference to AdoDB?

    Cor
    Success
    Cor
    Thursday, July 30, 2009 4:00 PM
  • Thank you Cor and Paul for your friendly help.

    Hi nathan,

    Welcome to MSDN forums!

    As Paul said, it's simpler and efficient to use ADO.NET to connect and access MS Access 2003/2007 database.
    Code sample:

    Imports System.Data.OleDb

    Public Class Form1

        'Binding database table to DataGridView

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\mydb2007.accdb;Persist Security Info=False;")

            'Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=D:\myDB2003.mdb")

            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Table1", con)

            con.Open()

            Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)

            Dim myDataSet As DataSet = New DataSet()

            myDA.Fill(myDataSet, "MyTable")

            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

            con.Close()

            con = Nothing

        End Sub

    End Class



    However, you still can use ADO to access database in VB.NET, but you need to add reference "Microsoft ActiveX Data Object Library" to your project as Cor said.

    Please check this article/example for detailed instruction.
    Article: Using ADODB Services in .NET WinForms Applications in VB.NET
    http://www.vbdotnetheaven.com/UploadFile/ptailor/ADODBServices04082005081324AM/ADODBServices.aspx
    This article walks you through the usage of ADODB services in .NET application using VB.NET language. The example details the data access using ADODB, fetching recordset, filling ADO.NET dataset from the recordset and binding the same to datagrid for user display.




    Best regards,
    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback on our support, please contact msdnmg@microsoft.com
    Wednesday, August 05, 2009 6:50 AM