Free2Code
 
Time: 2008-11-21, 09:52pm
how to connect VB to SQl Server 2000
Subject: how to connect VB to SQl Server 2000  ·  Posted: 2004-09-03, 02:10am
Rank: Unregistered
hi..would like to know how to connect vb6 to sql server..when connect to Microsoft access, i used the following code but what about in SQl server 2000? any good website to recommend?thanks.

Dim cn As New ADODB.Connection
Dim provStr As String
cn.Provider = "sqloledb"
provStr = "Server=(local);Database=test2;Trusted_Connection=yes"
cn.Open provStr

Private Sub Command1_Click()

Dim strsql As String <--how to do it in Sql Server 2000??
strsql = "select * from patient "
mrscust.Source = strsql
Set mrscust.ActiveConnection = cn
mrscust.Open
mrscust.AddNew
mrscust.Fields("PatientID" = PatientID.Text
mrscust.Fields("PatientName" = PatientName.Text
mrscust.Update
mrscust.Close

End Sub
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2004-09-07, 02:23am
Rank: ? (4821)
Member #: 3416
i would expect that the only difference would be in the provStr, but i'm not sure what you need to change it to.

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2004-09-15, 07:51am
Rank: Unregistered
Set cnn = New ADODB.Connection

' Open a connection by referencing the ODBC driver.
cnn.ConnectionString = "driver={SQL Server};" & _
"server=???;uid=;pwd=;database=???"
cnn.Open
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB.net to SQl Server 2000  ·  Posted: 2004-10-24, 02:18am
Rank: Unregistered
how to connect VB.net to SQl Server 2000
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2004-11-01, 08:10pm
Rank: Unregistered
this is the way how i conected my vb with oracle..

Global OraSession As Object
Global OraDatabaseOthers As Object

Sub Main()

Set OraSession = CreateObject("OracleInProcServer.XOraSession"
Set OraDatabaseOthers = OraSession.OpenDatabase("tv3prod", "cma/crm", 0&

End Sub

so, how can i modify this codes so that i can connect it to sql server?

 
  Reply to this ·  Post link ·  Top
This post has been removed by a moderator (reason: smiley spam)
 
  Top
This post has been removed by a moderator (reason: smiley spam)
 
  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-02-03, 05:24pm
Rank: Unregistered
have this
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-02-11, 01:25am
Rank: Unregistered
Code for Connect and Execute Buttons


'********* Connect Command Button Code **************
Private Sub cmdConnect_Click()
On Error Resume Next

' Validate user supplied login arguments
' ... validation code goes here

'Create connect string from user input box values
strConnect = "Provider=SQLOLEDB.1" _
& ";User ID=" & Me!txtUID _
& ";Password=" & Me!txtPWD _
& ";Initial Catalog=" & Me!txtDatabase _
& ";Data Source=" & Me!txtServer

Screen.MousePointer = vbHourglass

'Call sub to test connect string
If TestConnectString(strConnect) = False Then
strMsg = "Server not found or login invalid."
MsgBox strMsg, vbExclamation, "Error"
'Exit the routine because there was an error
Else
'Toggle command buttons and text boxes appropriately
'... do stuff here
End If

Screen.MousePointer = vbNormal

End Sub

'********* Test Connect String Sub **************
Function TestConnectString(ByVal sConn As String) As Boolean
On Error Resume Next

Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection

'TestConnectString initializes to False by default
cnn.Open sConn

'No error means that the connect string works!
If Err.Number = 0 Then TestConnectString = True

' Clean up and release resources
cnn.Close
Set cnn = Nothing

End Function

'********* Execute Command Button Code **************
Private Sub cmdExecute_Click()
On Error Resume Next

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field

Dim strMsg As String
Dim strHeaders As String
Dim strResults As String

' Simple validation that SQL statement exists
If Len(Me!txtSQL) = 0 Then
strMsg = "Enter a valid SQL Statement."
MsgBox strMsg, vbExclamation, "Error"
Exit Sub
End If

MousePointer = vbHourglass

' Instantiate Connection and Recordset objects
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset

' Open Connection and Load Recordset
cnn.Open strConnect
rst.Open CStr(Me!txtSQL), cnn

' Create column headers
For Each fld In rst.Fields
strHeaders = strHeaders & UCase(fld.Name) & vbTab
Next

' Use the GetString method to retrieve recordset text
strResults = rst.GetString(adClipString, -1, vbTab, vbCrLf)

' Return header and data to results pane
Me!txtResults = strHeaders & vbCrLf & strResults

' If there was an error then replace the output
' text with the description of the error.
If Err.Number > 0 Then Me!txtResults = Err.Description

' Clean up and release resources
rst.Close
Set rst = Nothing
cnn.Close
Set cnn = Nothing

MousePointer = vbNormal

End Sub

 
  Reply to this ·  Post link ·  Top
Subject: how to connect VB.net to SQl Server 2000  ·  Posted: 2005-02-17, 04:46pm
Rank: Unregistered
Please provide me basic about connect vb.net to sql server 2000. how many way connect to sql server 2000 by use vb.net. how can I do if I want to print any table on sql server 2000 by write code.


My e-mail is : nolvanroth@yahoo.com

Best Regards,
Nol vanroth.
 
  Reply to this ·  Post link ·  Top
This post has been removed by a moderator (reason: double post)
 
  Top
Subject: Re: how to connect VB to SQl Server  ·  Posted: 2005-02-27, 08:05pm
Rank: Unregistered
Please provide me basic about connect vb and vb.net to sql server. how many way connect to sql server by use vb.net. how can I do if I want to print any table on sql server by write code.And what is diffe. in ADO and ADO.net


My e-mail is : shekh_mohasin@yahoo.om

Best Regards,
Shekh
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-03-03, 06:38pm
Rank: Unregistered
I have one method to connect VB to SQL 2000
Those are:
Step 1: You have to create one folder to store all of your files.
Step 2: You must save one notepad file into your created folder before and change its extension from " .txt " --> " .udl "
Step 3: Choose your Database name in your SQL 2000 and Click on Test Connection Button.
If your testing is successfull please close it.
Step 4:
In VB:

Dim cn as ADODB.connection
Dim rs as New ADODB.recordset
----------------
set cn=new ADODB.connect
cn.open "file name=' " & app.path & "\file.udl"
rs.open "TableName",cn
----------------
-----------------
-----------------

 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-03-04, 04:54pm
Rank: Unregistered
How to execute .sql file in Visual basic 6.0
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-03-04, 07:21pm
Rank: Unregistered
what i do with VB and sql server
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 7.0  ·  Posted: 2005-03-15, 09:55pm
Rank: Unregistered
reenakaundal@yahoo.co.in
 
  Reply to this ·  Post link ·  Top
This post has been removed by a moderator (reason: smiley spam)
 
  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-03-18, 02:12am
Rank: Unregistered
how to retrieve the second maximum value in the sql server
 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-04-17, 11:49am
Rank: Unregistered
result connect all test:

cnn.ConnectionString = "driver={SQL Server};" & _
"server=test;uid=;pwd=;database=test"

 
  Reply to this ·  Post link ·  Top
Subject: Re: how to connect VB to SQl Server 2000  ·  Posted: 2005-05-29, 06:28am
Rank: Unregistered
In relation with "SQL SERVER" so how would you put those tables appear in databound grids?
 
  Reply to this ·  Post link ·  Top

Pages: 1 · 2

Please login or register to post a reply.

icons