If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > connection string for VB6 form to sql server2000 DB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-03, 03:10
ishrat khan ishrat khan is offline
Registered User
 
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.....
Reply With Quote
  #2 (permalink)  
Old 11-03-03, 20:17
KarSoV KarSoV is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On