Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 13th, 2004, 12:33 PM
Registered User
 
Join Date: Jan 2004
Location: london, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use Visual Basic 6 connect to SQL server?

Hi,

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?

Thanks

Joanne
__________________
joanne
Reply With Quote
  #2 (permalink)  
Old January 13th, 2004, 12:58 PM
Authorized User
 
Join Date: Jun 2003
Location: Edinburgh, , United Kingdom.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

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"
Connection.Open
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.
Reply With Quote
  #3 (permalink)  
Old August 31st, 2006, 06:02 AM
Authorized User
 
Join Date: Dec 2005
Location: , , United Kingdom.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools
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 Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect to SQL Database with Visual Basic 2008 enizag VB Databases Basics 5 October 22nd, 2008 01:04 PM
Beginning Visual Basic SQL Server 7.0 code aqua Beginning VB 6 2 June 27th, 2005 05:31 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 10:32 AM



All times are GMT -4. The time now is 01:52 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.