Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 13th, 2004, 12:33 PM
Registered User
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use Visual Basic 6 connect to SQL server?


I am new to VB and Sql stored procedure.
Can any of you let me know how can I use VB6 connect to a DabaBase(AAA)in a local SQl server?


Old January 13th, 2004, 12:58 PM
Authorized User
Join Date: Jun 2003
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts


I'll give you a brief run down.......
1) You need to have a reference to ADO, done by selecting from the menu > Project > References and check Microsoft ActiveX Data Ojects 2.X Library (assuming you have mdac installed - get this from microsoft if you dont)
2) Create connection and command objects....(this should come up with intellisense if you have it installed properly)
Dim Connection As New ADODB.Connection
Dim Command As New ADODB.Command
3) Login....
Connection.ConnectionString = "driver={SQL Server};server=YOURSERVER;uid=YOURUSER;pwd=YOUPASS WORD;database=YOURDATABASE"
Command.ActiveConnection = Connection
4) Call your procedure
Dim ResultSet As New ADODB.Recordset
Command.CommandText = "YOURPROCEDURE"
Set ResultSet = Command.Execute
5) Work with you results
Dim value as String
If ResultSet.BOF = True And ResultSet.EOF = True Then
value = ResultSet.Fields(0)
End If

This is just 1 way, but it will give you an idea, but have a look for ADO on the net. You only asked for how to connect but I gave you the code to call a stored procedure also and this post should probably be in a VB thread.

I hope this helps.
Old August 31st, 2006, 05:02 AM
Authorized User
Join Date: Dec 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts

This doesn't work; I get 'compile error: invalid outside procedure'

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning Visual Basic SQL Server 7.0 code aqua Beginning VB 6 3 July 17th, 2018 07:51 PM
Connect to SQL Database with Visual Basic 2008 enizag VB Databases Basics 5 October 22nd, 2008 12:04 PM
Beginning SQL Server 2000 For Visual Basic Develop viper7 All Other Wrox Books 2 February 17th, 2005 02:07 PM
Visual Basic .NET and SQL Server 2000 rayap All Other Wrox Books 3 May 31st, 2004 09:32 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.