Last Update: 26 June 2008
Product: StarSQL
Version: 5.x
Article ID: SQV00SQ010
This document describes how to execute a DB2 query from a Visual Basic .NET application using the StarSQL software and the Microsoft ODBC.NET Data Provider.
This solution uses the STAFF table provided with the DB2 UDB Sample tables. Contact IBM to obtain a copy of this sample table. The sample code for adding a command button in step 7 is excerpted from Microsoft Knowledge Base Article 310985.
Imports System.Data
Imports Microsoft.Data.ODBC
Dim cn As OdbcConnection
Trycn = New OdbcConnection("DSN=STARSQL_DSN;UID=DB2USER;PWD=PASSWORD;")
Dim mystring As String = "SELECT NAME FROM <SCHEMA>.STAFF"
Dim cmd As OdbcCommand = New OdbcCommand(mystring, cn)
cn.Open()
Dim dr As OdbcDataReader = cmd.ExecuteReader()
While dr.Read
Console.WriteLine(dr.GetString(0))
End While
dr.Close()
Catch o As OdbcException
MsgBox(o.Message.ToString)
Finally
cn.Close()
End Try
The code executes the DB2 query and displays the result set. You should see the NAME column values of the STAFF table in the Output window.
The information in technical documents comes without any warranty. The author(s) or distributor(s) will not accept responsibility for any damage incurred directly or indirectly through use of the information contained in these documents. The information in technical documents may be gathered from various sources, including IBM, Microsoft, and other organizations.