Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    14

    connection string for VB6 form to sql server2000 DB

    Hi.
    I am new to sql server 2000. I want to connect my data entry form made in VB6 to the table in sql database. I know how to write connection string for Access but need help for sql server 2000. i know how to make ODBC connection.... but the problem lies with the code in the form.

    thanks in advance
    regards.....

  2. #2
    Join Date
    Oct 2003
    Location
    Portugal
    Posts
    4

    Re: connection string for VB6 form to sql server2000 DB

    You can do something like this!!!

    'Use as reference: Microsoft ActiveX Data Objects 2.X Library
    'Code:

    Public intConnection As ADODB.Connection

    Public Sub Open_Conn(Server_Name As String, Data_Base As String, Login As String, Password As String)
    Set intConnection = New ADODB.Connection
    intConnection.ConnectionString = "driver={SQL Server}" & _
    ";server=" & Server_Name & _
    ";uid=" & Login & _
    ";pwd=" & Password & _
    ";database=" & Data_Base
    intConnection.Open
    Activo = True
    End Sub

    Public Sub Close_Conn()
    intConnection.Close
    Set intConnection = Nothing
    End Sub

    Private Function Get_Value(Field As String, Table As String) As String
    Dim rstValue As ADODB.Recordset
    Dim strQry As String
    strQry = "SELECT " & Field & " FROM " & Table
    Set rstValue = New ADODB.Recordset
    rstValue.Open strQry, intConnection, adOpenStatic, adLockReadOnly, adCmdText
    If rstValue.EOF Then
    Get_Value = ""
    Else
    Get_Value = strQry(0)
    End If
    rstValue.Close
    Set rstValue = Nothing
    End Function

Posting Permissions

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