borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How 2 Create Sub reports in Crystal Report/Data Report?)Next Topic (Find the second largest salary from emp table) New Topic New Poll Post Reply
AndreaVB Forum : Database : connecting database witrh vb6
Poster Message
anurag_jain76
Level: Guest


icon connecting database witrh vb6

i m unable to connect ms access xp with vb6,
please help me how to connect MSAccess XP with vb6.
thanks in advance,.

01-12-2002 at 12:47 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: connecting database witrh vb6

You left out some important info.

Using DAO/ADO?

Access in XP format or 2000 format (2000 is the default for XP)?

How are you currently trying to connect (what's the connection string)?

What are you trying to connect with, controls or variables [ADODC1 control, or Dim cn as X.Connection (where X is DAO or ADO)]

(as a note, an 2002 Access format database can be read from with just an ADO control and grid, so the above is important to know)

[Edited by JLRodgers on 01-12-2002 at 05:44 PM GMT]

01-12-2002 at 11:40 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: connecting database witrh vb6

Hi, here's an excerpt from a class i wrote (packaged into a dll referenced EVERYWHERE i go! )
Const CONNECT_ACCESS97 = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" 'another property to be added to change jet version
Const CONNECT_ACCESS2000 = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" 'another property to be added to change jet version
Const CONNECT_SQL = "Provider=SQLOLEDB.1;Persist Security Info=False;"


Public Enum eDBType
    dbtAccess2000 = 0
    dbtAccess97 = 2
    dbtSQLServer = 1
End Enum
Private prvUID As String
Private prvPWD As String
Private prvDBType As eDBType
Private prvServer As String
Private prvDatabase As String
Public Property Let PWD(s As String)
    prvPWD = s
End Property
Public Property Get PWD() As String
    PWD = prvPWD
End Property

Public Property Let Server(s As String)
    prvServer = s
End Property
Public Property Get Server() As String
    Server = prvServer
End Property

Public Property Let DBtype(t As eDBType)
    prvDBType = t
End Property
Public Property Get DBtype() As eDBType
    DBtype = prvDBType
End Property
Public Property Let UID(s As String)
    prvUID = s
End Property
Public Property Get UID() As String
    UID = prvUID
End Property
Public Property Let Database(s As String)
    prvDatabase = s
End Property
Public Property Get Database() As String
    Database = prvDatabase
End Property

Private Function Check() As Boolean
    ' Return TRUE if all required properties have been filled
    Dim msg As String
    msg = ""
    
    Select Case prvDBType
        Case dbtAccess2000, dbtAccess97
            If prvDatabase = "" Then msg = "Database"
        Case dbtSQLServer
            If prvDatabase = "" Then msg = "Database"
            If prvServer = "" Then msg = "Server"
            If prvUID = "" Then msg = "UID"
            
    End Select
    If msg <> "" Then
        Check = False
        MsgBox "Not all parameters were filled (missing " & msg & ")"
    Else
        Check = True
    End If
End Function
Public Property Get ConnectionString() As String
    Dim s As String
    
    If Not Check Then Exit Property
        
    Select Case prvDBType
        Case dbtAccess97
            s = CONNECT_ACCESS97 & Chr$(34) & prvDatabase & Chr$(34)
        Case dbtAccess2000
            s = CONNECT_ACCESS2000 & Chr$(34) & prvDatabase & Chr$(34)
        Case dbtSQLServer
            s = CONNECT_SQL
            s = s & " User ID=" & prvUID
            s = s & ";Data Source=" & prvServer
            s = s & ";Initial Catalog=" & prvDatabase
    End Select
    ConnectionString = s
End Property

Hope this helps,
it constructs the connection string for ADO.

Kieron

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

13-12-2002 at 01:33 AM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: connecting database witrh vb6

Oh yes, it doesn't set the network connection (er.. "default library=...") property, will add it if you wish.
This property is used to specify to use named pipes, tcp or dsn connectivity for sql server (some corporations require you to use tcp, EVEN tho they support dsn, dunno why)
Kieron

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

13-12-2002 at 01:36 AM
View Profile Send Email to User Show All Posts | Quote Reply
Chris_871
Level: Master


Registered: 30-11-2002
Posts: 106
icon Re: connecting database witrh vb6

You can use ADO to connect the ACCESS 2000 database

'Write the following code into the General Declaration

Dim con As New ADODB.Connection
Dim ConString As String
Dim Rs As New ADODB.Recordset

'In the form load event write the following code


ConString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
         "pwd=;" & _
         "UID=;" & _
         "DBQ=" & App.Path & "database.mdb"


con.Open ConString

Rs.Open "select * from tablename ", con,3,1



'you must select the reference

Microsoft ActiveX dataobject 2.0 Library

'Please check whether it works on XP or not.

Best wishes
By
Chris

13-01-2003 at 05:05 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : connecting database witrh vb6
Previous Topic (How 2 Create Sub reports in Crystal Report/Data Report?)Next Topic (Find the second largest salary from emp table) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder