473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

SQL connection

please give me the code to connect SQL to VB6.0
Sep 28 '06 #1
2 4624
sashi
1,754 Expert 1GB
Hi there,

Kindly refer to below attached link, hope it helps you to get started with, take care my fren.. :)

http://www.thescripts.com/forum/thread525605.html

please give me the code to connect SQL to VB6.0
Sep 28 '06 #2
Reena83
32
Hi there,

Kindly refer to below attached link, hope it helps you to get started with, take care my fren.. :)

http://www.thescripts.com/forum/thread525605.html
************************************************** ******************************************
How do we access an external database from Visual Basic?
To access an external database, we need to have the following items in our project:
1. The Microsoft ActiveX Data Objects Library (version 2.5 upwards)
2. A global variable that is used to connect to the database
3. A command to associate the global variable with the external file
4. An SQL string that specifies what data we would like to obtain from the external file
5. A modular variable (called a Recordset) that contains the output of the SQL statement that we use.
6. A command to fill the Recordset with the results of the SQL statement

From the Menu, go to Project �� References and the from the list, click on the
entry:
”Microsoft ActiveX Data Objects 2.__ Library” Versions 2.5 and above work fine.

In the main module, in the Option Explicit area, declare the variable as follows:
Public gcn_________ As New ADODB.Connection

In the main module, in the Option Explicit area, declare the variable as follows:
Public gcn_________ As New ADODB.Connection
Name the variable meaningfully, for example, gcnLibrary if you are accessing
the database Library.mdb

In the main module Sub Main(), type in the following code:
‘Find the directory path to the database
If Left(App.Path, 2) <> “\\” Then
ChDrive App.Path
End If
ChDir App.Path
‘Open the connection
gcn____.Open “Provider = Microsoft.Jet.OLEDB.4.0; Data Source = __.mdb”
NOTE: The database (.mdb) file must be in the same directory as the Visual Basic
Project (.vbp) file.

If you are going to display data from the database on a form on Form_Load, type
use this code in the Form_Load() subroutine:
‘create an SQL statement to obtain all records from tbl_______
Dim pst______SQL As String
pst______SQL = “Select * from tbl______”

In the Form’s Option Explicit section, declare a modular Recordset Variable
Option Explicit
Private mrs________ As New ADODB.Recordset
In Form_Load() , after creating your SQL string, fill in the recordset using the
following command:
mrs_____.Open pst__SQL, gcn___, adOpenStatic, adLockOptimistic, adCmdText


Hope it helps...Cheers
Sep 28 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: G-Fit | last post by:
Hello group, I have several servers hosting SQL databases. On each of them, I have several databases. All those databases have the same structure (even those on different servers), only the data...
11
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a...
6
by: Chris Szabo | last post by:
I've created a data access layer for a .NET web application. I'm using C# and framework 1.1. I'm getting an error from time to time when I close a connection saying: ...
18
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
3
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable...
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.