Sunteți pe pagina 1din 19

Using IBM DB2 UDB instead of

Microsoft Access with Visual Basic


Presented by DB2 Developer Domain
http://www7b.software.ibm.com/dmdd/

Table of Contents
If you're viewing this document online, you can click any of the topics below to link directly to that section.

1. Introduction.............................................................. 2
2. Step 1: Obtaining and installing the Microsoft sample ........... 4
3. Step 2: Create the DB2 database ................................... 5
4. Step 3: Copy the data source ........................................ 6
5. Step 4: Modify the Duwamish source code ........................ 7
6. Executing the DB2 application ....................................... 17
7. Summary ................................................................ 18

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 1 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

Section 1. Introduction

Objectives
Duwamish Books is a fictional bookstore created by Microsoft used to demonstrate an
extensive collection of sample database applications. The Duwamish samples evolve
from a relatively simple desktop database application to complex web-based
applications as the Duwamish business grows from a single store to an online
e-business.

These pages describe how to modify Phase 1 of Microsoft's Duwamish Books sample
database application to use a DB2 database as the data source, rather than a
Microsoft Access data source. This requires the use of IBM's OLE DB driver.

Audience
You should try this tutorial if:

• You have a Visual Basic database application that works with Microsoft Access, and
you want to set it up to use IBM DB2 and IBM's OLE DB driver. This tutorial outlines
the changes you will need to make to your application.
• You have a Visual Basic database application that works with DB2 using Microsoft's
OLE DB driver, and want to know what functionality IBM's driver supports. This
tutorial gives you means to compare how the two differ.
• You want to learn about database application development, OLE DB, Visual Basic,
or ADO by working through a sample application. This tutorial is large enough to
involve several complicated aspects of database application design and
development, but it is not overwhelming and can be understood quickly.

Requirements
In order to work through this tutorial, you will need:

• The Duwamish Books data source and application source code (both available to
download from the Microsoft website)
• Visual Basic 5.0 (or later) Professional or Enterprise Edition
• DB2 Version 7 (FixPak 3 or later) with the latest IBM OLE DB Driver

Time investment
Page 2 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

Once you have obtained the Microsoft sample code, several tasks must be completed:

1. Copy the initial data from the Duwamish Access data source into a DB2 data source.
To create and fill the DB2 data source with the information from the Access data
source should take 5 minutes, using the tool provided.
2. Modify the application source code. Making these code changes can take anywhere
from thirty minutes to several hours, depending on your familiarity with Visual Basic,
ADO, and the Duwamish application.

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 3 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

Section 2. Step 1: Obtaining and installing the Microsoft


sample

Obtaining and installing the Microsoft sample


Go to Microsoft's Duwamish Books, Phase 1 Setup and Source Code web site to
retrieve the sample setup package and source code for the first phase of the
Duwamish Books sample.

Alternatively, you can execute a search on Microsoft's main web page for Phase 1
Duwamish Books.

The web page has instructions for downloading and installing both the sample
application source code and the data source.

Once the download is complete, follow the instructions in the d1src.txt and d1app.txt
files that were included in the Duwamish sample.

The Duwamish source files are set as read-only when installed. You will need to
change the file attributes to read/write before you modify the files in the following steps.
To do this, use Windows Explorer to find and highlight all the files in the directory.
Right-click on the files and choose Properties from the menu. On the Properties page,
de-select the box beside Read-only. This will change the file attributes to read/write.

Page 4 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

Section 3. Step 2: Create the DB2 database

Create the DB2 database


In this step, we will create a DB2 database called "stage1" to store the Duwamish
source data.

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 5 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

Section 4. Step 3: Copy the data source

Copy the data source


Here is a Visual Basic project to convert the data in the Access data source.

This tool is intended to make data conversion from Access to DB2 easier. It is only a
generic conversion tool and is not covered by IBM DB2 support.

To use the conversion tool, open the project in Visual Basic and execute the
application through these steps:

1. In the appropriate text boxes, enter the Access data source name
Duwamish_Phase1, and the user identification and password. (If you don't know
what the password is, try leaving the user identification and password text boxes
blank.)
2. In the appropriate text boxes, enter the DB2 database source name stage1, and
the user identification and password. (Again, depending on your system
configuration, leaving the user identification and password text boxes blank will
cause the Windows login user identification and password to be used, which would
allow you to connect to the database.)
3. Click on the button labeled Connect To Access to connect to the Access data
source.
4. Click on the button labeled Connect to DB2 to connect to the DB2 database.
5. Click on the button labeled Create Empty Tables to examine the Access data
source and create corresponding tables in the DB2 database.
6. Click on the button labeled Fill DB2 Tables to copy the data in the Access data
source into the corresponding DB2 database table.
7. Disconnect from the data sources or close the application (which automatically
disconnects from the data sources). After experimenting with the Duwamish
application, if you want to reinitialize the "stage 1" DB2 database so that it contains
the same data as Duwamish_Phase1, the Access data source, you can run the
conversion application again. Clicking on the Create/Empty DB2 Tables button will
drop the current tables in "stage 1" and recreate them, filling them with the data from
the Access data source.

Page 6 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

Section 5. Step 4: Modify the Duwamish source code

Modify the Duwamish source code


All of the required sample code changes are caused by one of the following:

1. Some SQL statements in the Duwamish application must be modified to work with
DB2. Also, DB2 uses 0 and 1 integer values, instead of Boolean data types to
represent "true" and "false." Therefore, every time the application tries to insert a
boolean value into the stage1 database, that boolean value must be converted to a 0
or 1 integer value.
2. IBM's OLE DB driver does not currently support server side cursors. Every instance
of an ADO DB connection (and one particular instance of an ADO DB recordset)
must have the "CursorLocation" property set to "adUseClient". In addition, whenever
the primary key value that DB2 generates automatically in the identity column of a
table is required by the Duwamish application, a Requery must be called to retrieve
that information from the database to the application.
3. Some minor errors within the Duwamish application cause incorrect behavior. These
errors are easily fixed, but make a big difference to the application behavior.
4. The format of a DB2 timestamp data type is different from the equivalent Windows
date type. For this reason, extra work needs to be done to get date and time
information into DB2 from the Duwamish application.

The following pages list the changes that need to be made to the Duwamish code. If a
fix is not applied, we provide a description of the possible behavior of the application.

Step 4a: "Launch" project changes


Modify the "Launch" project to use the DB2 database, stage1:

In the "CommonConstants" module, (cmnconst.bas), If this is not done, the application will look for a
replace the line Microsoft database named "Duwamish_Phase1."
Public Const scDSN = "Duwamish_Phase1"
with the line
Public Const scDSN =
"provider=ibmdadb2;DSN=stage1"

Step 4b: "Catalog" project changes


Modify the "Catalog" project to change various SQL statements into valid DB2 SQL:

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 7 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

In the code for the form "frmSearch" (search.frm), in If this is not done, the error "Run-time error
the function "btnGo_Click", replace the line '-2147217903 (80040e11)': [DB2/NT]
SQL0206N "PUBLISHER" is not valid in
strSQL = strSQL & "Publisher LIKE '%" the context where it is used.
... SQLSTATE=42703" occurs when a search is
with the line performed in the "Catalog" application with the
"Publisher" box checked (in an "Advanced" search).
strSQL = strSQL & "Publishers.LastName This syntax causes an error, regardless of which
LIKE '%"... data source is used.
In the code for the form "frmSearch" (search.frm), in If this is not done, the error "Run-time error
the function "btnGo_Click", replace the line '-2147217903 (80040e11)': [DB2/NT]
SQL0206N "SUPPLIER" is not valid in the
strSQL = strSQL & "Supplier LIKE '%" context where it is used.
... SQLSTATE=42703" occurs when a search is
with the line performed in the "Catalog" application with the
"Supplier" box checked. This syntax causes an error,
strSQL = strSQL & "Suppliers.LastName regardless of which data source is used.
LIKE '%"...

Modify the "Catalog" project to give DB2 integer values for Boolean types:

In the code for the form "frmSearch" (search.frm), in If this is not done, the error "Run-time error
the function "btnGo_Click", replace the line '-2147217903 (80040e11)': [DB2/NT]
SQL0206N "TRUE" is not valid in the
strSQL = strSQL & "IsBook = TRUE" context where it is used.
with the line SQLSTATE=42703" occurs when a search is
executed in the "Catalog" application for items which
strSQL = strSQL & "IsBook = 1" are books.
In the code for the form "frmSearch" (search.frm), in If this is not done, the error "Run-time error
the function "btnGo_Click", replace the line '-2147217903 (80040e11)': [DB2/NT]
SQL0206N "FALSE" is not valid in the
strSQL = strSQL & "IsBook = FALSE" context where it is used.
with the line SQLSTATE=42703" occurs when a search is
executed in the "Catalog" application for items which
strSQL = strSQL & "IsBook = 0" are not books.

Modify the "Catalog" project to use client side cursors:

In the code for the form "frmContact" (contact.frm), in


the function "UpdateButton_Click", after the line
Set oConn = New ADODB.Connection
add the line
oConn.CursorLocation = adUseClient
In the code for the form "frmContact" (contact.frm), in If this is not done, the error "Run-time error
the function "UpdateButton_Click", add the variable '94': Invalid use of NULL" occurs when
the "Create" button is clicked. This error occurs while
Dim bookmark As Variant a new supplier is being created from within the
and just before the line "Catalog" application by clicking on the New Item

Page 8 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

mnID = oRec!PKId button.


add the lines
bookmark = oRec.Bookmark
oRec.Requery
oRec.Bookmark = bookmark
In the code for the form "frmItem" (item.frm), in the
function "btnUpdate_Click", after the line
Set oConn = New ADODB.Connection
add the line
oConn.CursorLocation = adUseClient
In the code for the form "frmItem" (item.frm), in the If this is not done, the error "Run-time error
function "btnAddAuthor_Click", add the variable '94': Invalid use of NULL" occurs when
the Add button (beside "Author") is clicked when
Dim bookmark As Variant creating a new item in the "Catalog" application.
and just before the line
mnAuthorID = oRec!PKId
add the lines
bookmark = oRec.Bookmark
oRec.Requery
oRec.Bookmark = bookmark
In the code for the form "frmItem" (item.frm), in the If this is not done, the error "Run-time error
function "btnAddItemType_Click", add the variable '94': Invalid use of NULL" occurs when the
Add button (beside "ItemType") is clicked when
Dim bookmark As Variant creating a new item in the "Catalog" application.
and just before the line
mnItemTypeID = oRec!PKId
add the lines
bookmark = oRec.Bookmark
oRec.Requery
oRec.Bookmark = bookmark
In the "CatalogCommon" module (catalog.bas), in If this is not done, the error "Run-time error
the function "GetRecordset", after the line '380': Invalid Property Value" occurs
when the New Item button is clicked in the "Catalog"
Set oADO = New ADODB.Recordset application.
add the line
oADO.CursorLocation = adUseClient

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 9 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

Step 4c: "Orderent" project changes


Modify the "Orderent" project because DB2 doesn't allow boolean types:

In the "OrderCommon" module (order.bas), at the


If this is not done, the error "Run-time error
top with the constant declarations, replace the lines
'-2147217903 (80040e11)': [DB2/NT]
SQL0206N "FALSE" is not valid in the
Private Const scSELECT_PURCHASE_ ... context where it is used.
IsSales=False" SQLSTATE=42703" occurs when the button "Open
Private Const scSELECT_SALES_ORDERS ... PO" (for the first line) is clicked in the "Order Entry"
IsSales=True" application. The same message (with "TRUE"
replacing "FALSE") occurs when the button "Open
with the lines SO" (for the second line) is clicked in the "Order
Entry" application.
Private Const scSELECT_PURCHASE_ ...
IsSales=0"
Private Const scSELECT_SALES_ORDERS ...
IsSales=1"
In the "OrderCommon" module (order.bas), in the If this is not done, then any purchase orders created
function "InsertOrder", replace the line in the "Orders" application do not show up when the
Open PO button is clicked in the "Order Entry"
If .IsSales Then oRset!IsSales = application.
.IsSales
with the line
If .IsSales Then oRset!IsSales = 1 Else
oRset!IsSales = 0
In the "OrderCommon" module (order.bas), in the
If this is not done, the error "Run-time error
function "Update", after the comment "' Updating an
'-2147217903 (80040e11)': [DB2/NT]
Order", replace the line SQL0206N "FALSE" is not valid in the
context where it is used.
... " = " & VToSQL(.IsSales, icOTHER) & SQLSTATE=42703" occurs when a purchase order
_ is updated. (The update is executed by selecting
with the line Ordered in the menu "Order" after choosing one of
the purchase orders listed after the button "Open
... " = " & VToSQL(abs(CInt(.IsSales)), PO" in the "Order Entry" application.)
icOTHER) & _

Modify the "Orderent" project to use client side cursors:

In the "OrderCommon" module (order.bas), in the If this is not done, the error "Run-time error '3251':
function "InsertOrder", after the line Object or provider is not capable of performing
requested operation." occurs when the "Submit"
Set oConn = New ADODB.Connection button is clicked when a new purchase order is
add the line being created in the "Order Entry" application.

oConn.CursorLocation = adUseClient
In the "OrderCommon" module (order.bas), in the If this is not done, the error "Run-time error

Page 10 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

function "InsertOrder", add the variable '94': Invalid use of NULL" occurs when
the Submit button is clicked when creating a new
Dim bookmark As Variant purchase order in the "Order Entry" application.
and just before the line
lOrderId = oRset!PKId
add the lines
bookmark = oRset!Bookmark
oRset.Requery
oRset!Bookmark = bookmark
In the "DataAccessAPI" module (data_api.bas), in
the function "CacheConnection", after the line
Set m_oCachedConnection = New
ADODB.Connection
add the line
m_oCachedConnection.CursorLocation =
adUseClient
In the "DataAccessAPI" module (data_api.bas), in
each of the functions "ExecQuery", "GetRecordset",
"PutRecordSet", and "DataComponentsInstalled",
after the line
Set oConn = New ADODB.Connection
add the line
oConn.CursorLocation = adUseClient

Modify the "Orderent" project so that the date and time data is correctly formatted for
DB2:

In the "OrderCommon" module (order.bas), above This change is related to the next change.
the function "VToSQL", add the function
Private Function db2Date(sDate As
String)
db2Date = Year(sDate) & "-" &
Month(sDate) & "-" & Day(sDate) & " " &
_
Format$(Hour(sDate),"HH") & ":" & _
Format$(Minute(sDate),"mm") & ":" & _
Format$(Second(sDate),"ss") & ".000000"
End Function
In the "OrderCommon" module (order.bas), in the If this is not done, the error "Run-time error
function "VToSQL", replace the line '-2147467259 (80004005)': [DB2/NT]

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 11 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

VToSQL = scSQ & CStr(vVar) & scSQ SQL0180N. The syntax of the string
representation of a datetime value is
with the line incorrect. SQLSTATE=22007" occurs when a
VToSQL = scSQ & db2Date(CStr(vVar)) & user logged in as an Administrator tries to update an
scSQ employee's "Hire Date" by filling in the "Hire Date"
text row with anything other than a valid date in the
format "yyyy-mm-dd hh:mm:ss".

Step 4d: "POS" project changes


Modify the "POS" project because DB2 doesn't allow boolean types:

In the "POSCommon" module (pos.bas), in the If this is not done, the pull-down list "Sale Order" is
function "InsertSale", replace the line not initialized correctly in the "Shipping" application,
and the pull-down list "Purchase Order" is not
If .IsSales Then oRset!IsSales = initialized correctly in the "Receiving" application.
.IsSales
with the line
If .IsSales Then oRset!IsSales = 1 Else
oRset!IsSales = 0
In the "POSCommon" module (pos.bas), in the If this is not done, the pull-down list "Sale Order" is
function "InsertSale", replace the line not initialized correctly in the "Shipping" application.
oRset("Ship") = oSale.Ship
with the line
If oSale.Ship Then oRset("Ship") = 1
Else oRset("Ship") = 0
In the "POSCommon" module (pos.bas), in the If this is not done, the pull-down list "Sale Order" is
function "InsertSale", replace the line not initialized correctly in the "Shipping" application.
oRset!IsSale = True
with the line
oRset!IsSale = 1

Modify the "POS" project to use client-side cursors:

In the "POSCommon" module (pos.bas), in the If this is not done, the error "Run-time error
function "InsertSale" after the line '3251': Object or provider is not
capable of performing requested
Set oConn = New ADODB.Connection operation." occurs when the "Submit" button is
add the line clicked in the "POS" application.

oConn.CursorLocation = adUseClient
In the "POSCommon" module (pos.bas), in the If these lines are not added above oOrder.PKId =
function "InsertSale" add the variable oRset!PKId,the error "Run-time error '94':

Page 12 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

Dim bookmark As Variant Invalid use of NULL" occurs when the Submit
button is clicked in the "POS" application and Ship is
and above each of the lines selected from the "Sale" menu.
oOrder.PKId = oRset!PKId
if these lines are not added above oSale.PKId =
oSale.PKId = oRset("PKId") oRset("PKId") or oSaleDet.PKId = oRset!PKId,
oSaleDet.PKId = oRset!PKId the error "Run-time error '3251': Object
or provider is not capable of
add the lines performing requested operation." occurs
when the Submit button is clicked in the "POS"
bookmark = oRset.Bookmark
application.
oRset.Requery
oRset.Bookmark = bookmark

Modify the "POS" project to correct the generated SQL. This is not a requirement of the
IBM OLE DB driver, but it corrects the behavior of the Duwamish application:

In the "POSCommon" module (pos.bas), in the If this is not done, when x number of some stock
function "InsertSale", replace the line item is sold, the in-stock amount for all items is
reduced by x.
sQry = "SELECT Items.InStock FROM ...
oSaleDet.ItemId
with the line
sQry = "SELECT Items.InStock,
Items.PKID From Items"
and above the line
oRset.Open sQry, , , , adCmdText
add the line
oRset.Filter = "PKId=" &
oSaleDet.ItemId

Step 4e: "ShipRecv" project changes


Modify the "ShipRecv" project to change various SQL statements into valid DB2 SQL:

In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "System Error
function "Initialize", replace the line &80004005 (-2147467259). Unspecified
Error." occurs when the Shipping button or the
"[Authors].[FirstName] & ' ' & Receiving button is clicked in the "Launch Control"
[Authors].[LastName] " & _ application. This syntax causes the same error to
with the line occur, regardless of the data source.

"Authors.FirstName||'
'||Authors.LastName " & _

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 13 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "InitializeSaleOrders", replace the line '-2147467259 (80004005)': CLI0118E
Invalid SQL Syntax. SQLSTATE=37000"
sSQL = "SELECT DISTINCTROW occurs when the down arrow is clicked to get the
SaleDetails.* .. pull-down list "Sale Order" in the "Shipping"
with the line application.

sSQL = "SELECT DISTINCT SaleDetails.*


..
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "InitializePurchaseOrders", replace the line '-2147467259 (80004005)': CLI0118E
Invalid SQL Syntax. SQLSTATE=37000"
sSQL = "SELECT DISTINCTROW occurs when the down arrow is clicked to get the
OrderDetails.*, " & _ pull-down list "Purchase Order" in the "Receiving"
with the line application.

sSQL = "SELECT DISTINCT OrderDetails.*,


" & _
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "OrderComplete", replace the line '-2147467259 (80004005)': CLI0118E
Invalid SQL Syntax. SQLSTATE=37000"
sQry = "SELECT DISTINCTROW occurs when the Submit button is clicked in the
SaleDetails.* " & _ "Shipping" application.
with the line
sQry = "SELECT DISTINCT SaleDetails.* "
& _
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "OrderComplete", replace the line '-2147467259 (80004005)': CLI0118E
Invalid SQL Syntax. SQLSTATE=37000"
sQry = "SELECT DISTINCTROW occurs when the Submit button is clicked in the
OrderDetails.* " & _ "Receiving" application.
with the line
sQry = "SELECT DISTINCT OrderDetails.*
" & _
In the "CodeBase" module (CodeBase.bas), in the If the #'s are not replaced, the error "Run-time
function "ProcessItem", there are two problems with error '-2147467259 (80004005)':
the lines [DB2/NT] SQL0103N The numeric literal
"29#" is not valid. SQLSTATE=42604"
", " & .IsSale & ", " & .Quantity & ", occurs when the Submit button is clicked in the
#" & _ "Shipping" application.
.TransactionDate & "#, '" & .Notes &
"')" if the boolean is not converted to an integer, the
error "Run-time error '-2147217903
Replace the #'s with single quotes, and convert the (80040e11)': [DB2/NT] SQL0206N "TRUE"
boolean ".IsSales" to an integer by replacing these is not valid in the context where it is
lines with used. SQLSTATE=42703" occurs when the
", " & Abs(CInt(.IsSale)) & ", " & Submit button is clicked in the "Shipping"
.Quantity & ", '" & _ application.

Page 14 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

.TransactionDate & "', '" & .Notes &


"')"

Modify the "ShipRecv" project because DB2 doesn't allow boolean types:

In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "System Error
function "Initialize", replace the line &H80040E11 (-2147217903)." occurs when the
Shipping button is clicked in the "Launch Control"
"Items.AuthorId WHERE application.
(((Itemtype.IsBook)=True))"
with the line
"Items.AuthorId WHERE
(((Itemtype.IsBook)=1))"
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "System Error
function "Initialize", replace the line &H80040E11 (-2147217903)." occurs when the
Shipping button is clicked in the "Launch Control"
.. 'Supplier') AND application.
((Itemtype.IsBook)=False))"
with the line
.. 'Supplier') AND
((Itemtype.IsBook)=0))"
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "InitializeSaleOrders", replace the line '-2147217903 (80040e11)': [DB2/NT]
SQL0206N "TRUE" is not valid in the
"') AND ((Orders.IsSales)=True) AND context where it is used.
((Sales.Ship)=True))" SQLSTATE=42703" occurs when the down arrow is
with the line clicked to get the pull-down list "Sale Order" in the
"Shipping" application.
"') AND ((Orders.IsSales)=1) AND
((Sales.Ship)=1))"
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "InitializeSaleOrders", replace the line '-2147217903 (80040e11)': [DB2/NT]
SQL0206N "TRUE" is not valid in the
.. IsSales)=True) AND context where it is used.
((InventoryTrack.IsSale)=True)) " & _ SQLSTATE=42703" occurs when the down arrow is
with the line clicked to get the pull-down list "Sale Order" in the
"Shipping" application.
.. IsSales)=1) AND
((InventoryTrack.IsSale)=1)) " & _
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "InitializePurchaseOrders", replace the line '-2147217903 (80040e11)': [DB2/NT]
SQL0206N "FALSE" is not valid in the
"') AND ((Orders.IsSales)=False))" context where it is used.
with the line SQLSTATE=42703" occurs when the down arrow is
clicked to get the pull-down list "Sale Order" in the
"') AND ((Orders.IsSales)=0))" "Receiving" application.
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "InitializePurchaseOrders", replace the line '-2147217903 (80040e11)': [DB2/NT]

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 15 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

"((Orders.IsSales)=False) AND SQL0206N "FALSE" is not valid in the


((InventoryTrack.IsSale)=False)) " & _ context where it is used.
SQLSTATE=42703" occurs when the down arrow is
with the line clicked to get the pull-down list "Sale Order" in the
"((Orders.IsSales)=0) AND "Receiving" application.
((InventoryTrack.IsSale)=0)) " & _

Modify the "ShipRecv" project to fix a small code error that greatly affects the behavior
of the "Shipping" application:

In the "CodeBase" module (CodeBase.bas), in the If this is not done, the items in the "Sale Order
function "GetItem", replace the line Details" box at the bottom of the "Shipping"
application which supposedly belong to the sale
Set oItem = g_oBooks(iCount) order chosen from the pull-down list "Sale Order" are
with the line not the correct items.

Set oItem = g_oBooks(iCount2)

Modify the "ShipRecv" project so that the date and time data is correctly formatted for
DB2:

In the "CodeBase" module (CodeBase.bas), above This change is related to the next change.
the function "ProcessItem", add the function
Private Function db2Date(sDate As
String)
db2Date = Year(sDate) & "-" &
Month(sDate) & "-" & Day(sDate) & " " &
_
Format$(Hour(sDate),"HH") & ":" & _
Format$(Minute(sDate),"mm") & ":" & _
Format$(Second(sDate),"ss") & ".000000"
End Function
In the "CodeBase" module (CodeBase.bas), in the If this is not done, the error "Run-time error
function "ProcessItem", replace the line '-2147467259 (80004005)': [DB2/NT]
SQL0408N. A value is not compatible
.TransactionDate & "', '" & .Notes & with the data type of its assignment
"')" target. Target name is
with the line "TRANSACTIONDATE". SQLSTATE=42821"
occurs when the Submit button is clicked in the
db2Date(.TransactionDate) & "', '" & "Receiving" application.
.Notes & "')"

Page 16 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

Section 6. Executing the DB2 application

Executing the DB2 application


After completing all the code changes, execute the program to ensure it functions
properly.

• Compile all the project modules


• Run "Launch.exe" to execute the application. The user ID for logging on to the
Duwamish application must be entered in uppercase. The password can be in either
uppercase or lower case.

If any problems arise, see the next section.

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 17 of 19
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain

Section 7. Summary

Troubleshooting
The previous pages document the required changes to the sample application code.
Beside each change is a description of the application behavior, or the error message
that appears if the change is not made properly. If you encounter an error message
when the application is running, or if the application exhibits unusual behavior (for
example, if tables are not being correctly updated), then search the descriptions on the
previous pages to see if your trouble is related to one of the changes listed.

Further troubleshooting
• If you have checked through the list of possible troubles and cannot find anything
that corresponds to your situation, try modifying the "Orderent", "POS", and
"ShipRecv" projects so that they run as stand alone applications. Then they can be
debugged from within the Visual Basic environment.
• To run as stand alone applications, the "Orderent" and "POS" projects require
modification of the private subroutine Form_Load(). Check the source code for
comments like "The following code prevents stand alone execution." Comment out
the code that prevents the application from running stand alone, so that the
application can be executed and debugged from within the Visual Basic
programming environment.
• In the "ShipRecv" project, the same project is used to run both the Shipping and
Receiving applications, so the required changes are a little more difficult. You must
force the execution within the Form_Load() subroutine to flow through the code path
related to either Shipping or Receiving, depending on which application you are
trying to debug. Comment out any code that directs the flow away from the
application you are debugging.
• If the "Microsoft ActiveX Data Objects Library" is not available when opening the
Project -> References menu in Visual Basic, go to the Project -> Component menu
and check the corresponding component.

Your feedback

Trademarks
DB2 is a registered trademark of the IBM Corporation in the United States and/or other
countries.

Page 18 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/

Windows is a trademarks of Microsoft Corporation in the United States, other countries,


or both.

Other company, product and service names may be trademarks or service marks of
others.

Colophon
This tutorial was written entirely in XML, using the developerWorks Toot-O-Matic tutorial
generator. The open source Toot-O-Matic tool is an XSLT stylesheet and several XSLT
extension functions that convert an XML file into a number of HTML pages, a zip file, JPEG
heading graphics, and two PDF files. Our ability to generate multiple text and binary formats
from a single source file illustrates the power and flexibility of XML. (It also saves our
production team a great deal of time and effort.)

You can get the source code for the Toot-O-Matic at


www6.software.ibm.com/dl/devworks/dw-tootomatic-p. The tutorial Building tutorials with the
Toot-O-Matic demonstrates how to use the Toot-O-Matic to create your own tutorials.
developerWorks also hosts a forum devoted to the Toot-O-Matic; it's available at
www-105.ibm.com/developerworks/xml_df.nsf/AllViewTemplate?OpenForm&RestrictToCategory=11.
We'd love to know what you think about the tool.

Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 19 of 19

S-ar putea să vă placă și