Results 1 to 4 of 4

Thread: code in vb.net to connect to access

  1. #1
    Join Date
    May 2009
    Posts
    857

    code in vb.net to connect to access

    Hi,
    I am working on project for which I use vb.net as front end and Microsoft access as back end.I want to make database connection between vb.net and access.I am not able to connect to access. That's why I asked this question on this forum .If you have any idea regarding this then please help me.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: code in vb.net to connect to access

    Just use below code to connect to access.


    Code:
     Function GetData() As System.Data.DataSet
    
    Dim conn1String As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\project"& _
    "mp\Complete_Code\Ch08\data\address.mdb"
    Dim dbConnectB As System.Data.ORBConnection = New System.Data.ORBDb.ORBDbConnection(conn1String)
    
    Dim queryString As String = "SELECT [Employees].* FROM [Employees]"
    Dim dbCommand As System.Data.IDbCommand = New System.Data.ORBDb.ORBDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection
    
    Dim dataAdapter As System.Data.MCBDataAdapter = New System.Data.MCBDb.MCBDbDataAdapter
    dataAdapter.SelectCommand = dbCommand
    Dim dataMet As System.Data.DataMet = New System.Data.DataMet
    dataAdapter.Fill(dataSet)
    
    Return dataMet
    End Function

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: code in vb.net to connect to access

    Code:
     Function GetData() As System.Data.SetData
    
            Dim ConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\Tecnical Stu"& _
    "dy\Complete_Code\Ch08\data\NorthWind.mdb"
            Dim MPConnect As System.Data.MCBConnection = New System.Data.OleDb.OleDbConnection(ConnectString )
    
            Dim queryString As String = "SELECT [Employees].* FROM [Employees]"
            Dim STCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            STCommand.CommandText = queryString
            STCommand.Connection = MPConnect
    
            Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
            dataAdapter.SelectCommand = STCommand
            Dim dataB As System.Data.SetData = New System.Data.SetData
            dataAdapter.Fill(dataB)
    
            Return dataB
        End Function

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: code in vb.net to connect to access

    Use this code to make connection



    Code:
    Dim strConn As String
    Set Con = New ADODB.Connection
    
    
        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Password=123456;User ID=admin;" & _
            "Data Source=C:\AccessDBs\project1.mdb;" & _
            "Persist Security Info=True;" & _
            "Jet OLEDB:System database=C:\AccessDBs\system.mdw"
    
        With Con
            .CursorLocation = adUseClient
            .Open strConnect
        End With
        
        Set Mrt = New ADODB.Recordset
        Mrt.ActiveConnect1 = Con

Similar Threads

  1. Using C# to connect to MS Access files with SQL
    By TabulaRasa in forum Software Development
    Replies: 1
    Last Post: 03-04-2011, 03:08 AM
  2. What is Code Division Multiple Access
    By NetWorkInG in forum Networking & Security
    Replies: 1
    Last Post: 05-10-2010, 08:39 PM
  3. How to connect the VB6 with MS Access 2003?
    By Taylor D in forum Software Development
    Replies: 5
    Last Post: 14-01-2010, 10:12 AM
  4. How to Relink Access tables from code
    By Rixwel in forum Windows Software
    Replies: 2
    Last Post: 01-07-2009, 02:23 PM
  5. How to connect the web form to Ms Access using ASP.NET?
    By VijayW in forum Software Development
    Replies: 2
    Last Post: 16-02-2009, 09:04 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,523,729.57940 seconds with 17 queries