Solved

ODBC 3.0 and VB

Posted on 1997-06-01
2
315 Views
Last Modified: 2006-11-17
Trying to use ODBC 3.0 with VB4, unfortunately all examples in ODBC 3.0 SDK are in C language, any idea
from where I can get VB examples on a Internet, can you
write at least SQL AllocHandle part for me in VB.
Thank a million
Matthew
0
Comment
Question by:mativare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
markbob061097 earned 50 total points
ID: 1426685
The following is what I use to connect to an ODBC database.  You must supply the values for the gsDataSource (ODBC Datasource), gsUserID (Database UserID), and gsPassword (Database password) variables.  If the fODBCConnect returns a 0 then it connected to the database correctly.

A book that has a chapter on ODBC programming in Visual Basic which I learned from is "Teach Yourself Database Programming with Visual Basic 4" from SAMS Publishing.

' 32-bit ODBC API Declares (Remove 32 from dll for 16-bit systems)
  Declare Function SQLAllocEnv Lib "odbc32.dll" (env As Long) As Integer
  Declare Function SQLAllocConnect Lib "odbc32.dll" (ByVal env As Long, hdbc As Long) As Integer
  Declare Function SQLAllocStmt Lib "odbc32.dll" (ByVal hdbc As Long, hstmt As Long) As Integer
  Declare Function SQLConnect Lib "odbc32.dll" (ByVal hdbc As Long, ByVal Server As String, ByVal serverlen As Integer, ByVal uid As      String, ByVal uidlen As Integer, ByVal pwd As String, ByVal pwdlen As Integer) As Integer

' SQL/ODBC Constants
  Public Const SQL_SUCCESS = 0
  Public Const SQL_NO_DATA_FOUND = 100

' ODBC Variables
  Public glHenv As Long           ' Environment Handle
  Public glHdbc As Long           ' Database Connection
  Public glHstmt As Long          ' Statement Handle
  Public gsDataSource As String   ' Data Source Name (You Provide Value)
  Public gsUserID As String       ' User ID (You Provide Value)
  Public gsPassword As String     ' User Password (You Provide Value)

Public Function fODBCConnect() As Integer

    ' Declare Variables
        Dim nResult As Integer

    ' Get Environment Handle
        nResult = SQLAllocEnv(glHenv)
    If nResult = SQL_SUCCESS Then
    ' Get Connection Handle
        nResult = SQLAllocConnect(glHenv, glHdbc)
    If nResult = SQL_SUCCESS Then
    ' Connect to Database
        nResult = SQLConnect(glHdbc, gsDataSource, Len(gsDataSource), gsUserID, Len(gsUserID), gsPassword, Len(gsPassword))
    If nResult = SQL_SUCCESS Then
    ' Get Statement Handle
        nResult = SQLAllocStmt(glHdbc, glHstmt)
    End If
    End If
    End If

    ' Set Return Value
        fODBCConnect = nResult

End Function
0
 
LVL 1

Author Comment

by:mativare
ID: 1426686
Response excelent, but still in your sample ODBC 2,0 used
I was looking for ODBC 3.0 sample. It all begins with
SQLAllocHandle(), SQlAllocEnv() is obsolete in ODBC 3.0
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 6 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question