access to db2
TRANSCRIPT
Using IBM DB2 UDB instead ofMicrosoft Access with Visual Basic
Presented by DB2 Developer Domain
http://www7b.software.ibm.com/dmdd/
Table of ContentsIf you're viewing this document online, you can click any of the topics below to link directly to that section.
1. Introduction.............................................................. 22. Step 1: Obtaining and installing the Microsoft sample ........... 43. Step 2: Create the DB2 database ................................... 54. Step 3: Copy the data source ........................................ 65. Step 4: Modify the Duwamish source code ........................ 76. Executing the DB2 application ....................................... 177. Summary ................................................................ 18
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 1 of 19
Section 1. Introduction
Objectives
Duwamish Books is a fictional bookstore created by Microsoft used to demonstrate anextensive collection of sample database applications. The Duwamish samples evolvefrom a relatively simple desktop database application to complex web-basedapplications as the Duwamish business grows from a single store to an onlinee-business.
These pages describe how to modify Phase 1 of Microsoft's Duwamish Books sampledatabase application to use a DB2 database as the data source, rather than aMicrosoft 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, andyou want to set it up to use IBM DB2 and IBM's OLE DB driver. This tutorial outlinesthe changes you will need to make to your application.
• You have a Visual Basic database application that works with DB2 using Microsoft'sOLE DB driver, and want to know what functionality IBM's driver supports. Thistutorial 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 toinvolve several complicated aspects of database application design anddevelopment, 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 todownload 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
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 2 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
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 datasource should take 5 minutes, using the tool provided.
2. Modify the application source code. Making these code changes can take anywherefrom thirty minutes to several hours, depending on your familiarity with Visual Basic,ADO, and the Duwamish application.
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 3 of 19
Section 2. Step 1: Obtaining and installing the Microsoftsample
Obtaining and installing the Microsoft sample
Go to Microsoft's Duwamish Books, Phase 1 Setup and Source Code web site toretrieve the sample setup package and source code for the first phase of theDuwamish Books sample.
Alternatively, you can execute a search on Microsoft's main web page for Phase 1Duwamish Books.
The web page has instructions for downloading and installing both the sampleapplication source code and the data source.
Once the download is complete, follow the instructions in the d1src.txt and d1app.txtfiles that were included in the Duwamish sample.
The Duwamish source files are set as read-only when installed. You will need tochange 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.
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 4 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
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 Duwamishsource data.
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 5 of 19
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 ageneric conversion tool and is not covered by IBM DB2 support.
To use the conversion tool, open the project in Visual Basic and execute theapplication through these steps:
1. In the appropriate text boxes, enter the Access data source nameDuwamish_Phase1, and the user identification and password. (If you don't knowwhat the password is, try leaving the user identification and password text boxesblank.)
2. In the appropriate text boxes, enter the DB2 database source name stage1, andthe user identification and password. (Again, depending on your systemconfiguration, leaving the user identification and password text boxes blank willcause the Windows login user identification and password to be used, which wouldallow you to connect to the database.)
3. Click on the button labeled Connect To Access to connect to the Access datasource.
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 datasource and create corresponding tables in the DB2 database.
6. Click on the button labeled Fill DB2 Tables to copy the data in the Access datasource into the corresponding DB2 database table.
7. Disconnect from the data sources or close the application (which automaticallydisconnects from the data sources). After experimenting with the Duwamishapplication, if you want to reinitialize the "stage 1" DB2 database so that it containsthe same data as Duwamish_Phase1, the Access data source, you can run theconversion application again. Clicking on the Create/Empty DB2 Tables button willdrop the current tables in "stage 1" and recreate them, filling them with the data fromthe Access data source.
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 6 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
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 withDB2. Also, DB2 uses 0 and 1 integer values, instead of Boolean data types torepresent "true" and "false." Therefore, every time the application tries to insert aboolean value into the stage1 database, that boolean value must be converted to a 0or 1 integer value.
2. IBM's OLE DB driver does not currently support server side cursors. Every instanceof an ADO DB connection (and one particular instance of an ADO DB recordset)must have the "CursorLocation" property set to "adUseClient". In addition, wheneverthe primary key value that DB2 generates automatically in the identity column of atable is required by the Duwamish application, a Requery must be called to retrievethat information from the database to the application.
3. Some minor errors within the Duwamish application cause incorrect behavior. Theseerrors 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 Windowsdate type. For this reason, extra work needs to be done to get date and timeinformation into DB2 from the Duwamish application.
The following pages list the changes that need to be made to the Duwamish code. If afix 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),replace the line
Public Const scDSN = "Duwamish_Phase1"
with the line
Public Const scDSN ="provider=ibmdadb2;DSN=stage1"
If this is not done, the application will look for aMicrosoft database named "Duwamish_Phase1."
Step 4b: "Catalog" project changes
Modify the "Catalog" project to change various SQL statements into valid DB2 SQL:
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 7 of 19
In the code for the form "frmSearch" (search.frm), inthe function "btnGo_Click", replace the line
strSQL = strSQL & "Publisher LIKE '%"...
with the line
strSQL = strSQL & "Publishers.LastNameLIKE '%"...
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "PUBLISHER" is not valid inthe context where it is used.SQLSTATE=42703" occurs when a search isperformed in the "Catalog" application with the"Publisher" box checked (in an "Advanced" search).This syntax causes an error, regardless of whichdata source is used.
In the code for the form "frmSearch" (search.frm), inthe function "btnGo_Click", replace the line
strSQL = strSQL & "Supplier LIKE '%"...
with the line
strSQL = strSQL & "Suppliers.LastNameLIKE '%"...
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "SUPPLIER" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when a search isperformed in the "Catalog" application with the"Supplier" box checked. This syntax causes an error,regardless of which data source is used.
Modify the "Catalog" project to give DB2 integer values for Boolean types:
In the code for the form "frmSearch" (search.frm), inthe function "btnGo_Click", replace the line
strSQL = strSQL & "IsBook = TRUE"
with the line
strSQL = strSQL & "IsBook = 1"
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "TRUE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when a search isexecuted in the "Catalog" application for items whichare books.
In the code for the form "frmSearch" (search.frm), inthe function "btnGo_Click", replace the line
strSQL = strSQL & "IsBook = FALSE"
with the line
strSQL = strSQL & "IsBook = 0"
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "FALSE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when a search isexecuted in the "Catalog" application for items whichare not books.
Modify the "Catalog" project to use client side cursors:
In the code for the form "frmContact" (contact.frm), inthe 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), inthe function "UpdateButton_Click", add the variable
Dim bookmark As Variant
and just before the line
If this is not done, the error "Run-time error'94': Invalid use of NULL" occurs whenthe "Create" button is clicked. This error occurs whilea new supplier is being created from within the"Catalog" application by clicking on the New Item
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 8 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
mnID = oRec!PKId
add the lines
bookmark = oRec.Bookmark
oRec.Requery
oRec.Bookmark = bookmark
button.
In the code for the form "frmItem" (item.frm), in thefunction "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 thefunction "btnAddAuthor_Click", add the variable
Dim bookmark As Variant
and just before the line
mnAuthorID = oRec!PKId
add the lines
bookmark = oRec.Bookmark
oRec.Requery
oRec.Bookmark = bookmark
If this is not done, the error "Run-time error'94': Invalid use of NULL" occurs whenthe Add button (beside "Author") is clicked whencreating a new item in the "Catalog" application.
In the code for the form "frmItem" (item.frm), in thefunction "btnAddItemType_Click", add the variable
Dim bookmark As Variant
and just before the line
mnItemTypeID = oRec!PKId
add the lines
bookmark = oRec.Bookmark
oRec.Requery
oRec.Bookmark = bookmark
If this is not done, the error "Run-time error'94': Invalid use of NULL" occurs when theAdd button (beside "ItemType") is clicked whencreating a new item in the "Catalog" application.
In the "CatalogCommon" module (catalog.bas), inthe function "GetRecordset", after the line
Set oADO = New ADODB.Recordset
add the line
oADO.CursorLocation = adUseClient
If this is not done, the error "Run-time error'380': Invalid Property Value" occurswhen the New Item button is clicked in the "Catalog"application.
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 9 of 19
Step 4c: "Orderent" project changes
Modify the "Orderent" project because DB2 doesn't allow boolean types:
In the "OrderCommon" module (order.bas), at thetop with the constant declarations, replace the lines
Private Const scSELECT_PURCHASE_ ...IsSales=False"
Private Const scSELECT_SALES_ORDERS ...IsSales=True"
with the lines
Private Const scSELECT_PURCHASE_ ...IsSales=0"
Private Const scSELECT_SALES_ORDERS ...IsSales=1"
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "FALSE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when the button "OpenPO" (for the first line) is clicked in the "Order Entry"application. The same message (with "TRUE"replacing "FALSE") occurs when the button "OpenSO" (for the second line) is clicked in the "OrderEntry" application.
In the "OrderCommon" module (order.bas), in thefunction "InsertOrder", replace the line
If .IsSales Then oRset!IsSales =.IsSales
with the line
If .IsSales Then oRset!IsSales = 1 ElseoRset!IsSales = 0
If this is not done, then any purchase orders createdin the "Orders" application do not show up when theOpen PO button is clicked in the "Order Entry"application.
In the "OrderCommon" module (order.bas), in thefunction "Update", after the comment "' Updating anOrder", replace the line
... " = " & VToSQL(.IsSales, icOTHER) &_
with the line
... " = " & VToSQL(abs(CInt(.IsSales)),icOTHER) & _
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "FALSE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when a purchase orderis updated. (The update is executed by selectingOrdered in the menu "Order" after choosing one ofthe purchase orders listed after the button "OpenPO" in the "Order Entry" application.)
Modify the "Orderent" project to use client side cursors:
In the "OrderCommon" module (order.bas), in thefunction "InsertOrder", after the line
Set oConn = New ADODB.Connection
add the line
oConn.CursorLocation = adUseClient
If this is not done, the error "Run-time error '3251':Object or provider is not capable of performingrequested operation." occurs when the "Submit"button is clicked when a new purchase order isbeing created in the "Order Entry" application.
In the "OrderCommon" module (order.bas), in the If this is not done, the error "Run-time error
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 10 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
function "InsertOrder", add the variable
Dim bookmark As Variant
and just before the line
lOrderId = oRset!PKId
add the lines
bookmark = oRset!Bookmark
oRset.Requery
oRset!Bookmark = bookmark
'94': Invalid use of NULL" occurs whenthe Submit button is clicked when creating a newpurchase order in the "Order Entry" application.
In the "DataAccessAPI" module (data_api.bas), inthe function "CacheConnection", after the line
Set m_oCachedConnection = NewADODB.Connection
add the line
m_oCachedConnection.CursorLocation =adUseClient
In the "DataAccessAPI" module (data_api.bas), ineach 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 forDB2:
In the "OrderCommon" module (order.bas), abovethe function "VToSQL", add the function
Private Function db2Date(sDate AsString)
db2Date = Year(sDate) & "-" &Month(sDate) & "-" & Day(sDate) & " " &_
Format$(Hour(sDate),"HH") & ":" & _
Format$(Minute(sDate),"mm") & ":" & _
Format$(Second(sDate),"ss") & ".000000"
End Function
This change is related to the next change.
In the "OrderCommon" module (order.bas), in thefunction "VToSQL", replace the line
If this is not done, the error "Run-time error'-2147467259 (80004005)': [DB2/NT]
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 11 of 19
VToSQL = scSQ & CStr(vVar) & scSQ
with the line
VToSQL = scSQ & db2Date(CStr(vVar)) &scSQ
SQL0180N. The syntax of the stringrepresentation of a datetime value isincorrect. SQLSTATE=22007" occurs when auser logged in as an Administrator tries to update anemployee's "Hire Date" by filling in the "Hire Date"text row with anything other than a valid date in theformat "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 thefunction "InsertSale", replace the line
If .IsSales Then oRset!IsSales =.IsSales
with the line
If .IsSales Then oRset!IsSales = 1 ElseoRset!IsSales = 0
If this is not done, the pull-down list "Sale Order" isnot initialized correctly in the "Shipping" application,and the pull-down list "Purchase Order" is notinitialized correctly in the "Receiving" application.
In the "POSCommon" module (pos.bas), in thefunction "InsertSale", replace the lineoRset("Ship") = oSale.Ship
with the line
If oSale.Ship Then oRset("Ship") = 1Else oRset("Ship") = 0
If this is not done, the pull-down list "Sale Order" isnot initialized correctly in the "Shipping" application.
In the "POSCommon" module (pos.bas), in thefunction "InsertSale", replace the line
oRset!IsSale = True
with the line
oRset!IsSale = 1
If this is not done, the pull-down list "Sale Order" isnot initialized correctly in the "Shipping" application.
Modify the "POS" project to use client-side cursors:
In the "POSCommon" module (pos.bas), in thefunction "InsertSale" after the line
Set oConn = New ADODB.Connection
add the line
oConn.CursorLocation = adUseClient
If this is not done, the error "Run-time error'3251': Object or provider is notcapable of performing requestedoperation." occurs when the "Submit" button isclicked in the "POS" application.
In the "POSCommon" module (pos.bas), in thefunction "InsertSale" add the variable
If these lines are not added above oOrder.PKId =oRset!PKId,the error "Run-time error '94':
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 12 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Dim bookmark As Variant
and above each of the lines
oOrder.PKId = oRset!PKId
oSale.PKId = oRset("PKId")
oSaleDet.PKId = oRset!PKId
add the lines
bookmark = oRset.Bookmark
oRset.Requery
oRset.Bookmark = bookmark
Invalid use of NULL" occurs when the Submitbutton is clicked in the "POS" application and Ship isselected from the "Sale" menu.
if these lines are not added above oSale.PKId =oRset("PKId") or oSaleDet.PKId = oRset!PKId,the error "Run-time error '3251': Objector provider is not capable ofperforming requested operation." occurswhen the Submit button is clicked in the "POS"application.
Modify the "POS" project to correct the generated SQL. This is not a requirement of theIBM OLE DB driver, but it corrects the behavior of the Duwamish application:
In the "POSCommon" module (pos.bas), in thefunction "InsertSale", replace the line
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
If this is not done, when x number of some stockitem is sold, the in-stock amount for all items isreduced by x.
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 thefunction "Initialize", replace the line
"[Authors].[FirstName] & ' ' &[Authors].[LastName] " & _
with the line
"Authors.FirstName||''||Authors.LastName " & _
If this is not done, the error "System Error&80004005 (-2147467259). UnspecifiedError." occurs when the Shipping button or theReceiving button is clicked in the "Launch Control"application. This syntax causes the same error tooccur, regardless of the data source.
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 13 of 19
In the "CodeBase" module (CodeBase.bas), in thefunction "InitializeSaleOrders", replace the line
sSQL = "SELECT DISTINCTROWSaleDetails.* ..
with the line
sSQL = "SELECT DISTINCT SaleDetails.*..
If this is not done, the error "Run-time error'-2147467259 (80004005)': CLI0118EInvalid SQL Syntax. SQLSTATE=37000"occurs when the down arrow is clicked to get thepull-down list "Sale Order" in the "Shipping"application.
In the "CodeBase" module (CodeBase.bas), in thefunction "InitializePurchaseOrders", replace the line
sSQL = "SELECT DISTINCTROWOrderDetails.*, " & _
with the line
sSQL = "SELECT DISTINCT OrderDetails.*," & _
If this is not done, the error "Run-time error'-2147467259 (80004005)': CLI0118EInvalid SQL Syntax. SQLSTATE=37000"occurs when the down arrow is clicked to get thepull-down list "Purchase Order" in the "Receiving"application.
In the "CodeBase" module (CodeBase.bas), in thefunction "OrderComplete", replace the line
sQry = "SELECT DISTINCTROWSaleDetails.* " & _
with the line
sQry = "SELECT DISTINCT SaleDetails.* "& _
If this is not done, the error "Run-time error'-2147467259 (80004005)': CLI0118EInvalid SQL Syntax. SQLSTATE=37000"occurs when the Submit button is clicked in the"Shipping" application.
In the "CodeBase" module (CodeBase.bas), in thefunction "OrderComplete", replace the line
sQry = "SELECT DISTINCTROWOrderDetails.* " & _
with the line
sQry = "SELECT DISTINCT OrderDetails.*" & _
If this is not done, the error "Run-time error'-2147467259 (80004005)': CLI0118EInvalid SQL Syntax. SQLSTATE=37000"occurs when the Submit button is clicked in the"Receiving" application.
In the "CodeBase" module (CodeBase.bas), in thefunction "ProcessItem", there are two problems withthe lines
", " & .IsSale & ", " & .Quantity & ",#" & _
.TransactionDate & "#, '" & .Notes &"')"
Replace the #'s with single quotes, and convert theboolean ".IsSales" to an integer by replacing theselines with
", " & Abs(CInt(.IsSale)) & ", " &.Quantity & ", '" & _
If the #'s are not replaced, the error "Run-timeerror '-2147467259 (80004005)':[DB2/NT] SQL0103N The numeric literal"29#" is not valid. SQLSTATE=42604"occurs when the Submit button is clicked in the"Shipping" application.
if the boolean is not converted to an integer, theerror "Run-time error '-2147217903(80040e11)': [DB2/NT] SQL0206N "TRUE"is not valid in the context where it isused. SQLSTATE=42703" occurs when theSubmit button is clicked in the "Shipping"application.
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 14 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
.TransactionDate & "', '" & .Notes &"')"
Modify the "ShipRecv" project because DB2 doesn't allow boolean types:
In the "CodeBase" module (CodeBase.bas), in thefunction "Initialize", replace the line
"Items.AuthorId WHERE(((Itemtype.IsBook)=True))"
with the line
"Items.AuthorId WHERE(((Itemtype.IsBook)=1))"
If this is not done, the error "System Error&H80040E11 (-2147217903)." occurs when theShipping button is clicked in the "Launch Control"application.
In the "CodeBase" module (CodeBase.bas), in thefunction "Initialize", replace the line
.. 'Supplier') AND((Itemtype.IsBook)=False))"
with the line
.. 'Supplier') AND((Itemtype.IsBook)=0))"
If this is not done, the error "System Error&H80040E11 (-2147217903)." occurs when theShipping button is clicked in the "Launch Control"application.
In the "CodeBase" module (CodeBase.bas), in thefunction "InitializeSaleOrders", replace the line
"') AND ((Orders.IsSales)=True) AND((Sales.Ship)=True))"
with the line
"') AND ((Orders.IsSales)=1) AND((Sales.Ship)=1))"
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "TRUE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when the down arrow isclicked to get the pull-down list "Sale Order" in the"Shipping" application.
In the "CodeBase" module (CodeBase.bas), in thefunction "InitializeSaleOrders", replace the line
.. IsSales)=True) AND((InventoryTrack.IsSale)=True)) " & _
with the line
.. IsSales)=1) AND((InventoryTrack.IsSale)=1)) " & _
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "TRUE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when the down arrow isclicked to get the pull-down list "Sale Order" in the"Shipping" application.
In the "CodeBase" module (CodeBase.bas), in thefunction "InitializePurchaseOrders", replace the line
"') AND ((Orders.IsSales)=False))"
with the line
"') AND ((Orders.IsSales)=0))"
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]SQL0206N "FALSE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when the down arrow isclicked to get the pull-down list "Sale Order" in the"Receiving" application.
In the "CodeBase" module (CodeBase.bas), in thefunction "InitializePurchaseOrders", replace the line
If this is not done, the error "Run-time error'-2147217903 (80040e11)': [DB2/NT]
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 15 of 19
"((Orders.IsSales)=False) AND((InventoryTrack.IsSale)=False)) " & _
with the line
"((Orders.IsSales)=0) AND((InventoryTrack.IsSale)=0)) " & _
SQL0206N "FALSE" is not valid in thecontext where it is used.SQLSTATE=42703" occurs when the down arrow isclicked to get the pull-down list "Sale Order" in the"Receiving" application.
Modify the "ShipRecv" project to fix a small code error that greatly affects the behaviorof the "Shipping" application:
In the "CodeBase" module (CodeBase.bas), in thefunction "GetItem", replace the line
Set oItem = g_oBooks(iCount)
with the line
Set oItem = g_oBooks(iCount2)
If this is not done, the items in the "Sale OrderDetails" box at the bottom of the "Shipping"application which supposedly belong to the saleorder chosen from the pull-down list "Sale Order" arenot the correct items.
Modify the "ShipRecv" project so that the date and time data is correctly formatted forDB2:
In the "CodeBase" module (CodeBase.bas), abovethe function "ProcessItem", add the function
Private Function db2Date(sDate AsString)
db2Date = Year(sDate) & "-" &Month(sDate) & "-" & Day(sDate) & " " &_
Format$(Hour(sDate),"HH") & ":" & _
Format$(Minute(sDate),"mm") & ":" & _
Format$(Second(sDate),"ss") & ".000000"
End Function
This change is related to the next change.
In the "CodeBase" module (CodeBase.bas), in thefunction "ProcessItem", replace the line
.TransactionDate & "', '" & .Notes &"')"
with the line
db2Date(.TransactionDate) & "', '" &.Notes & "')"
If this is not done, the error "Run-time error'-2147467259 (80004005)': [DB2/NT]SQL0408N. A value is not compatiblewith the data type of its assignmenttarget. Target name is"TRANSACTIONDATE". SQLSTATE=42821"occurs when the Submit button is clicked in the"Receiving" application.
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 16 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
Section 6. Executing the DB2 application
Executing the DB2 application
After completing all the code changes, execute the program to ensure it functionsproperly.
• Compile all the project modules
• Run "Launch.exe" to execute the application. The user ID for logging on to theDuwamish application must be entered in uppercase. The password can be in eitheruppercase or lower case.
If any problems arise, see the next section.
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 17 of 19
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 messagethat appears if the change is not made properly. If you encounter an error messagewhen the application is running, or if the application exhibits unusual behavior (forexample, if tables are not being correctly updated), then search the descriptions on theprevious 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 anythingthat corresponds to your situation, try modifying the "Orderent", "POS", and"ShipRecv" projects so that they run as stand alone applications. Then they can bedebugged from within the Visual Basic environment.
• To run as stand alone applications, the "Orderent" and "POS" projects requiremodification of the private subroutine Form_Load(). Check the source code forcomments like "The following code prevents stand alone execution." Comment outthe code that prevents the application from running stand alone, so that theapplication can be executed and debugged from within the Visual Basicprogramming environment.
• In the "ShipRecv" project, the same project is used to run both the Shipping andReceiving applications, so the required changes are a little more difficult. You mustforce the execution within the Form_Load() subroutine to flow through the code pathrelated to either Shipping or Receiving, depending on which application you aretrying to debug. Comment out any code that directs the flow away from theapplication you are debugging.
• If the "Microsoft ActiveX Data Objects Library" is not available when opening theProject -> References menu in Visual Basic, go to the Project -> Component menuand check the corresponding component.
Your feedback
Trademarks
DB2 is a registered trademark of the IBM Corporation in the United States and/or othercountries.
http://www7b.software.ibm.com/dmdd/ Presented by DB2 Developer Domain
Page 18 of 19 Using IBM DB2 UDB instead of Microsoft Access with Visual Basic
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 ofothers.
Colophon
This tutorial was written entirely in XML, using the developerWorks Toot-O-Matic tutorialgenerator. The open source Toot-O-Matic tool is an XSLT stylesheet and several XSLTextension functions that convert an XML file into a number of HTML pages, a zip file, JPEGheading graphics, and two PDF files. Our ability to generate multiple text and binary formatsfrom a single source file illustrates the power and flexibility of XML. (It also saves ourproduction team a great deal of time and effort.)
You can get the source code for the Toot-O-Matic atwww6.software.ibm.com/dl/devworks/dw-tootomatic-p. The tutorial Building tutorials with theToot-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 atwww-105.ibm.com/developerworks/xml_df.nsf/AllViewTemplate?OpenForm&RestrictToCategory=11.We'd love to know what you think about the tool.
Presented by DB2 Developer Domain http://www7b.software.ibm.com/dmdd/
Using IBM DB2 UDB instead of Microsoft Access with Visual Basic Page 19 of 19