Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB2 Host Variables in Visual Basic

Status
Not open for further replies.

allanhicks

Programmer
Aug 19, 2001
4
0
0
JP
Hi,
Can anyone tell me if it is possible to use DB2 host variables in Visual Basic. I have searched the documentation but can only find examples for C++ & COBOL. If it is possible could you provide a code sample on how to utilise them.

I have asked this in the DB2 forum but have received no replies.

Thanks,
Allan Hicks
 
Hi Allan,

I completed a project recently where I download DB2 table data from our mainframe to SQL server.

What is it you are trying to accomplish?

treesprite
 
Hi, I am trying to perform SQL queries on DB2 tables that return a single row result, eg

SELECT PRODUCT_NAME INTO :pNAME FROM PRODUCT_FILE WHERE PRODUCT_NAME = 'XXXX-XXX'

Where :pNAME is a 'host variable' as defined in the DB2 SQL guide. For example, in COBOL is could be defined as follows:

WORKING-STORAGE SECTION.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 PNAME PIC X(8).
EXEC SQL END DECLARE SECTION END-EXEC.

The question is how do I accomplish the same thing in Visual Basic?

Thanks,
Allan Hicks
 
Allan,

I am also using sql to query out DB2 data in visual basic. I have not tried the host variable approach but I do have an idea for you that has worked for me.

Put your sql into a string variable.

sqlline = &quot;SELECT PRODUCT_NAME FROM PRODUCT_FILE WHERE PRODUCT_NAME = &quot; & <productname variable>

Then open a recordset how you wish - i generally use ado

Now your recordset will have the queried product name. If more than one is returned you can also transverse the recordset to process each one.

I hope this helps!

:)

-S

 
allan -

I'm not sure you can use host variables in VB, as it typically requires a pointer to the address of the variable. I think you'll be better off if you use the DB2 ADO or OLEDB driver. Won't be as fast as using DB2's library, but definately more portable and easier to read.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top