[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Can this be done in ODBC.NET with VB.NET? (SQL Server stuff)

Bigtoga

7/26/2002 8:00:00 PM

-- please read from the bottom up as this originiated on the VB.ODBC boards.
Thanks to anyone who can help!

The code will mostly be the same ...
First do the SQLExecDirect. If the return code is SQL_SUCCESS_WITH_INFO,
then
call SQLGetDiagRec until the return code is SQL_NO_DATA.
SQLDiagRec will give you the SqlState and the ErrorMsg.
A brief overview of the VB code would be:


Const SQL_SUCCESS = 0
Const SQL_SUCCESS_WITH_INFO = 1
Const SQL_NO_DATA = 100

Public Declare Function SQLGetDiagRec Lib "ODBC32.DLL" (ByVal HandleType As
Integer, ByVal Handle As Long, ByVal RecNumber As Integer, ByVal Sqlstate
As
String, ByRef NativeErrorPtr As Long, ByVal MessageText As String, ByVal
BufferLength As Integer, ByRef TextLengthPtr As Integer) As Integer

..

retcode = SQLExecDirect(...)
If retcode = SQL_SUCCESS_WITH_INFO Then
Dim State As String, Message As String
Dim NativeError As Long, Length As Integer
retcode = SQLGetDiagRec(SQL_HANDLE_ENV, henv, 1, State, NativeError,
Message, Len(Message), Length)
End If

HTH,
-Tina
Microsoft Developer Support

> Hello -
>
> I am looking for any help on using
> SQLExecDirect and returning the SQL State and Error message text to VB or
> VB.NET using ODBC. I can find samples of how to do this in SS2K's BOL but
> they are for C++.
>
> I apologize if this info is readily available but I couldn't find it.
>
> If anyone has code samples, they are much appreciated. In fact - any help
is
> appreciated!
>
> Thanks!