2 Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
3 Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
4 Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
5 Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
6 Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
8 BorderStyle = 1 'Fixed Single
9 Caption = "DB2 Visual Basic Samples"
19 StartUpPosition = 3 'Windows Default
20 Begin VB.CommandButton cmdSample
21 Caption = "Create Sample DB"
29 Begin TabDlg.SSTab tabMain
41 TabCaption(0) = "Execute SQL"
42 TabPicture(0) = "Demo.frx":0000
43 Tab(0).ControlEnabled= -1 'True
44 Tab(0).Control(0)= "flxRecords"
45 Tab(0).Control(0).Enabled= 0 'False
46 Tab(0).Control(1)= "txtSQL"
47 Tab(0).Control(1).Enabled= 0 'False
48 Tab(0).Control(2)= "frmAutoCommit"
49 Tab(0).Control(2).Enabled= 0 'False
50 Tab(0).Control(3)= "cmdCommit"
51 Tab(0).Control(3).Enabled= 0 'False
52 Tab(0).Control(4)= "cmdRollback"
53 Tab(0).Control(4).Enabled= 0 'False
54 Tab(0).Control(5)= "chkAutoCommit"
55 Tab(0).Control(5).Enabled= 0 'False
56 Tab(0).Control(6)= "DataGridSQL"
57 Tab(0).Control(6).Enabled= 0 'False
58 Tab(0).Control(7)= "frmSamples"
59 Tab(0).Control(7).Enabled= 0 'False
60 Tab(0).Control(8)= "frmExecuteSQL"
61 Tab(0).Control(8).Enabled= 0 'False
62 Tab(0).Control(9)= "cmdSQLConnection"
63 Tab(0).Control(9).Enabled= 0 'False
64 Tab(0).Control(10)= "cmdSQLRecordset"
65 Tab(0).Control(10).Enabled= 0 'False
66 Tab(0).Control(11)= "cmdSQLCommand"
67 Tab(0).Control(11).Enabled= 0 'False
68 Tab(0).Control(12)= "cmdSQLSamples(0)"
69 Tab(0).Control(12).Enabled= 0 'False
70 Tab(0).Control(13)= "cmdSQLSamples(1)"
71 Tab(0).Control(13).Enabled= 0 'False
72 Tab(0).Control(14)= "cmdSQLSamples(2)"
73 Tab(0).Control(14).Enabled= 0 'False
74 Tab(0).Control(15)= "cmdSQLSamples(3)"
75 Tab(0).Control(15).Enabled= 0 'False
76 Tab(0).ControlCount= 16
77 TabCaption(1) = "Hierarchical Data"
78 TabPicture(1) = "Demo.frx":001C
79 Tab(1).ControlEnabled= 0 'False
80 Tab(1).Control(0)= "cmdHierarchy"
81 Tab(1).Control(1)= "hflxRecords"
82 Tab(1).Control(2)= "lblHierScript"
83 Tab(1).ControlCount= 3
84 TabCaption(2) = "LOBs"
85 TabPicture(2) = "Demo.frx":0038
86 Tab(2).ControlEnabled= 0 'False
87 Tab(2).Control(0)= "lblEmpno"
88 Tab(2).Control(1)= "lblLastname"
89 Tab(2).Control(2)= "lblFirstname"
90 Tab(2).Control(3)= "AdodcLob"
91 Tab(2).Control(4)= "cmdCLOB"
92 Tab(2).Control(5)= "cmdBLOB"
93 Tab(2).Control(6)= "cmdRefresh"
94 Tab(2).Control(7)= "txtEmpno"
95 Tab(2).Control(7).Enabled= 0 'False
96 Tab(2).Control(8)= "txtLastname"
97 Tab(2).Control(8).Enabled= 0 'False
98 Tab(2).Control(9)= "txtFirstname"
99 Tab(2).Control(9).Enabled= 0 'False
100 Tab(2).Control(10)= "txtClob"
101 Tab(2).Control(10).Enabled= 0 'False
102 Tab(2).Control(11)= "picBlob"
103 Tab(2).ControlCount= 12
104 TabCaption(3) = "Store Procedures"
105 TabPicture(3) = "Demo.frx":0054
106 Tab(3).ControlEnabled= 0 'False
107 Tab(3).Control(0)= "optStoredProcedures(11)"
108 Tab(3).Control(1)= "cmdShowSecondRS"
109 Tab(3).Control(2)= "DataGridSP"
110 Tab(3).Control(3)= "txtSPResult"
111 Tab(3).Control(4)= "cmdSPCall"
112 Tab(3).Control(5)= "optStoredProcedures(10)"
113 Tab(3).Control(6)= "optStoredProcedures(9)"
114 Tab(3).Control(7)= "optStoredProcedures(8)"
115 Tab(3).Control(8)= "optStoredProcedures(7)"
116 Tab(3).Control(9)= "optStoredProcedures(6)"
117 Tab(3).Control(10)= "optStoredProcedures(5)"
118 Tab(3).Control(11)= "optStoredProcedures(4)"
119 Tab(3).Control(12)= "optStoredProcedures(3)"
120 Tab(3).Control(13)= "optStoredProcedures(2)"
121 Tab(3).Control(14)= "optStoredProcedures(1)"
122 Tab(3).Control(15)= "optStoredProcedures(0)"
123 Tab(3).Control(16)= "frmStoredProcedures"
124 Tab(3).ControlCount= 17
125 TabCaption(4) = "UDFs"
126 TabPicture(4) = "Demo.frx":0070
127 Tab(4).ControlEnabled= 0 'False
128 Tab(4).Control(0)= "cmdUDFs(5)"
129 Tab(4).Control(1)= "cmdUDFs(4)"
130 Tab(4).Control(2)= "cmdUDFs(3)"
131 Tab(4).Control(3)= "cmdUDFs(2)"
132 Tab(4).Control(4)= "cmdUDFs(1)"
133 Tab(4).Control(5)= "cmdUDFs(0)"
134 Tab(4).Control(6)= "hflxGridUDF"
135 Tab(4).Control(7)= "txtUDF"
136 Tab(4).Control(7).Enabled= 0 'False
137 Tab(4).Control(8)= "Frame1"
138 Tab(4).ControlCount= 9
139 Begin VB.CommandButton cmdSQLSamples
149 Begin VB.CommandButton cmdSQLSamples
159 Begin VB.CommandButton cmdSQLSamples
169 Begin VB.CommandButton cmdSQLSamples
179 Begin VB.CommandButton cmdUDFs
189 Begin VB.CommandButton cmdUDFs
190 Caption = "SourcedColumnUDF"
199 Begin VB.CommandButton cmdUDFs
200 Caption = "ScUDFReturningErr"
209 Begin VB.CommandButton cmdUDFs
210 Caption = "ScratchpadScUDF"
219 Begin VB.CommandButton cmdUDFs
220 Caption = "ClobScalarUDF"
229 Begin VB.CommandButton cmdUDFs
230 Caption = "ScalarUDF"
239 Begin MSHierarchicalFlexGridLib.MSHFlexGrid hflxGridUDF
255 Begin VB.TextBox txtUDF
263 Strikethrough = 0 'False
269 ScrollBars = 2 'Vertical
275 Begin VB.Frame Frame1
276 Caption = "Work with UDF:"
283 Begin VB.OptionButton optStoredProcedures
284 Caption = "MAIN_EXAMPLE"
293 Begin VB.CommandButton cmdShowSecondRS
294 Caption = "Show Next RS"
302 Begin MSDataGridLib.DataGrid DataGridSP
317 AllowAddNew = -1 'True
318 AllowDelete = -1 'True
319 BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
320 Name = "MS Sans Serif"
326 Strikethrough = 0 'False
328 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
329 Name = "MS Sans Serif"
335 Strikethrough = 0 'False
338 BeginProperty Column00
341 BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
351 BeginProperty Column01
354 BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
366 BeginProperty Column00
368 BeginProperty Column01
372 Begin VB.TextBox txtSPResult
380 Strikethrough = 0 'False
389 Begin VB.CommandButton cmdSPCall
398 Begin VB.OptionButton optStoredProcedures
399 Caption = "DBINFO_EXAMPLE"
408 Begin VB.OptionButton optStoredProcedures
409 Caption = "DB2SQL_EXAMPLE"
418 Begin VB.OptionButton optStoredProcedures
419 Caption = "CLOB_EXTRACT"
428 Begin VB.OptionButton optStoredProcedures
429 Caption = "TWO_RESULT_SETS"
438 Begin VB.OptionButton optStoredProcedures
439 Caption = "ONE_RESULT_SET"
448 Begin VB.OptionButton optStoredProcedures
449 Caption = "DECIMAL_TYPE"
458 Begin VB.OptionButton optStoredProcedures
459 Caption = "ALL_DATA_TYPES"
468 Begin VB.OptionButton optStoredProcedures
469 Caption = "INOUT_PARAM"
478 Begin VB.OptionButton optStoredProcedures
479 Caption = "OUT_PARAM"
488 Begin VB.OptionButton optStoredProcedures
489 Caption = "IN_PARAMS"
498 Begin VB.OptionButton optStoredProcedures
499 Caption = "OUT_LANGUAGE"
508 Begin VB.Frame frmStoredProcedures
509 Caption = "Stored Procedure:"
516 Begin VB.CommandButton cmdSQLCommand
517 Caption = "on Command"
525 Begin VB.CommandButton cmdSQLRecordset
526 Caption = "on Recordset"
534 Begin VB.CommandButton cmdSQLConnection
535 Caption = "on Connection"
543 Begin VB.Frame frmExecuteSQL
544 Caption = "Execute SQL"
551 Begin VB.Frame frmSamples
558 Begin MSDataGridLib.DataGrid DataGridSQL
571 AllowAddNew = -1 'True
572 AllowDelete = -1 'True
573 BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
574 Name = "MS Sans Serif"
580 Strikethrough = 0 'False
582 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
583 Name = "MS Sans Serif"
589 Strikethrough = 0 'False
592 BeginProperty Column00
595 BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
605 BeginProperty Column01
608 BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
620 BeginProperty Column00
622 BeginProperty Column01
626 Begin VB.CheckBox chkAutoCommit
627 Caption = " AutoCommit"
636 Begin VB.CommandButton cmdRollback
645 Begin VB.CommandButton cmdCommit
654 Begin VB.Frame frmAutoCommit
661 Begin VB.PictureBox picBlob
662 BackColor = &H80000005&
672 Begin VB.TextBox txtClob
680 Strikethrough = 0 'False
692 Begin VB.TextBox txtFirstname
694 BackColor = &H80000013&
704 Begin VB.TextBox txtLastname
706 BackColor = &H80000013&
716 Begin VB.TextBox txtEmpno
718 BackColor = &H80000013&
728 Begin VB.CommandButton cmdRefresh
729 Caption = "Refresh Data"
737 Begin VB.CommandButton cmdBLOB
738 Caption = "Show Picture"
746 Begin VB.CommandButton cmdCLOB
747 Caption = "Show Resume"
755 Begin VB.CommandButton cmdHierarchy
764 Begin VB.TextBox txtSQL
772 Strikethrough = 0 'False
777 ScrollBars = 2 'Vertical
782 Begin MSHierarchicalFlexGridLib.MSHFlexGrid hflxRecords
798 Begin MSHierarchicalFlexGridLib.MSHFlexGrid flxRecords
814 Begin MSAdodcLib.Adodc AdodcLob
824 ConnectionTimeout= 15
836 BackColor = -2147483643
837 ForeColor = -2147483640
849 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
850 Name = "MS Sans Serif"
856 Strikethrough = 0 'False
860 Begin VB.Label lblHierScript
861 Caption = $"Demo.frx":008C
862 ForeColor = &H80000011&
869 Begin VB.Label lblFirstname
870 Caption = "First Name:"
877 Begin VB.Label lblLastname
878 Caption = "Last Name:"
885 Begin VB.Label lblEmpno
886 Caption = "Employee No.:"
894 Begin VB.CommandButton cmdVersionInfo
895 Caption = "Get Environment Info"
903 Begin VB.CommandButton cmdConnectInfo
904 Caption = "Get Connection Info"
912 Begin VB.CommandButton cmdConnectDataShape
913 Caption = "Connect DataShape"
920 Begin VB.CommandButton cmdConnectODBC
921 Caption = "Connect ODBC"
928 Begin VB.CommandButton cmdDisconnect
929 Caption = "Disconnect"
937 Begin VB.CommandButton cmdConnectOLEDB
938 Caption = "Connect OLE DB"
945 Begin VB.Frame frmConnection
946 Caption = "Connection:"
953 Begin VB.CommandButton cmdExit
961 Begin VB.Frame fmExit
968 Begin MSComctlLib.StatusBar sbrStatus
969 Align = 2 'Align Bottom
978 BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
980 BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
985 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
986 Name = "MS Sans Serif"
992 Strikethrough = 0 'False
995 Begin VB.Frame frmEnvironment
996 Caption = "Environment:"
1004 Attribute VB_Name = "frmMain"
1005 Attribute VB_GlobalNameSpace = False
1006 Attribute VB_Creatable = False
1007 Attribute VB_PredeclaredId = True
1008 Attribute VB_Exposed = False
1010 Private con As ADODB.Connection
1011 Private rst As ADODB.Recordset
1012 Private strMsgText As String
1013 Private wShowInstructions As Integer
1014 Private Sub cmdConnectOLEDB_Click()
1015 Set con = ConnectOLEDB()
1016 sbrStatus.Panels(1).Text = "Connect to sample database succeeded!"
1018 If wShowInstructions = vbYes Then
1019 ShowConnectionInstruction
1021 cmdConnectOLEDB_Exit:
1023 cmdConnectOLEDB_Error:
1024 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1025 If wShowInstructions = vbYes Then
1026 MsgBox "Connect to sample database failed!" & vbCr & _
1027 Err.Description & vbCr & _
1028 "Please correct the problem and try again.", _
1029 vbOKOnly + vbCritical, "Instruction"
1031 Resume cmdConnectOLEDB_Exit
1033 Private Sub cmdConnectODBC_Click()
1034 On Error GoTo cmdConnectODBC_Error
1035 Set con = ConnectODBC()
1036 sbrStatus.Panels(1).Text = "Connect to sample database succeeded!"
1038 If wShowInstructions = vbYes Then
1039 ShowConnectionInstruction
1041 cmdConnectODBC_Exit:
1043 cmdConnectODBC_Error:
1044 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1045 If wShowInstructions = vbYes Then
1046 MsgBox "Connect to sample database failed!" & vbCr & _
1047 Err.Description & vbCr & _
1048 "Please correct the problem and try again.", _
1049 vbOKOnly + vbCritical, "Instruction"
1051 Resume cmdConnectODBC_Exit
1053 Private Sub cmdConnectDataShape_Click()
1054 On Error GoTo cmdConnectDataShape_Error
1055 Set con = ConnectDataShape()
1056 con.Attributes = adXactCommitRetaining + adXactAbortRetaining
1057 sbrStatus.Panels(1).Text = "Connect to sample database succeeded!"
1059 cmdHierarchy.Enabled = True
1060 lblHierScript.ForeColor = vbButtonText
1061 If wShowInstructions = vbYes Then
1062 ShowConnectionInstruction
1064 cmdConnectDataShape_Exit:
1066 cmdConnectDataShape_Error:
1067 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1068 If wShowInstructions = vbYes Then
1069 MsgBox "Connect to sample database failed!" & vbCr & _
1070 Err.Description & vbCr & _
1071 "Please correct the problem and try again.", _
1072 vbOKOnly + vbCritical, "Instruction"
1074 Resume cmdConnectDataShape_Exit
1076 Private Sub EnableButtons()
1077 Dim tmpButton As CommandButton
1078 cmdConnectOLEDB.Enabled = False
1079 cmdConnectODBC.Enabled = False
1080 cmdConnectDataShape.Enabled = False
1081 cmdHierarchy.Enabled = False
1082 lblHierScript.ForeColor = vbGrayText
1083 cmdSample.Enabled = False
1084 cmdConnectInfo.Enabled = True
1085 cmdVersionInfo.Enabled = True
1086 cmdDisconnect.Enabled = True
1087 cmdRefresh.Enabled = True
1088 cmdSQLConnection.Enabled = True
1089 cmdSQLRecordset.Enabled = True
1090 cmdSQLCommand.Enabled = True
1091 For Each tmpButton In cmdSQLSamples
1092 tmpButton.Enabled = True
1094 cmdCommit.Enabled = False
1095 cmdRollback.Enabled = False
1096 chkAutoCommit.Enabled = True
1097 CheckAvailableStoredProcedures
1098 For Each tmpButton In cmdUDFs
1099 tmpButton.Enabled = True
1102 Private Sub ShowConnectionInstruction()
1103 MsgBox "Connect to sample database succeeded!" & vbCr & _
1104 "You may choose a Tab for specific functional demonstration," & vbCr & _
1105 "or press one of the info buttons for more information.", _
1106 vbOKOnly, "Instruction"
1108 Private Sub cmdDisconnect_Click()
1109 On Error GoTo cmdDisconnect_Error
1111 Set DataGridSQL.DataSource = Nothing
1112 Set hflxRecords.DataSource = Nothing
1113 DataGridSQL.ClearFields
1115 picBlob.Visible = False
1118 txtLastname.Text = ""
1119 txtFirstname.Text = ""
1120 AdodcLob.Caption = ""
1121 chkAutoCommit.Value = 1
1122 DataGridSP.Visible = False
1123 txtSPResult.Text = ""
1126 sbrStatus.Panels(1).Text = Disconnect(con)
1127 Dim tmpButton As CommandButton
1128 cmdConnectOLEDB.Enabled = True
1129 cmdConnectODBC.Enabled = True
1130 cmdConnectDataShape.Enabled = True
1131 cmdSample.Enabled = True
1132 cmdDisconnect.Enabled = False
1133 cmdHierarchy.Enabled = False
1134 lblHierScript.ForeColor = vbGrayText
1135 cmdConnectInfo.Enabled = False
1136 cmdVersionInfo.Enabled = False
1137 cmdSQLConnection.Enabled = False
1138 cmdSQLRecordset.Enabled = False
1139 cmdSQLCommand.Enabled = False
1140 For Each tmpButton In cmdSQLSamples
1141 tmpButton.Enabled = False
1143 cmdCommit.Enabled = False
1144 cmdRollback.Enabled = False
1145 chkAutoCommit.Enabled = False
1146 cmdRefresh.Enabled = False
1147 cmdBLOB.Enabled = False
1148 cmdCLOB.Enabled = False
1149 AdodcLob.Enabled = False
1150 cmdSPCall.Enabled = False
1151 CheckAvailableStoredProcedures
1152 For Each tmpButton In cmdUDFs
1153 tmpButton.Enabled = False
1155 If wShowInstructions = vbYes Then
1156 MsgBox "Sample Database is disconnected!" & vbCr & _
1157 "You may now choose one of the connections again.", _
1158 vbOKOnly, "Instruction"
1164 cmdDisconnect_Error:
1165 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1166 If wShowInstructions = vbYes Then
1167 MsgBox "Disconnect from sample database failed!" & vbCr & _
1168 Err.Description & vbCr & _
1169 "Please correct the problem and try again.", _
1170 vbOKOnly + vbCritical, "Instruction"
1172 Resume cmdDisconnect_Exit
1174 Private Sub cmdConnectInfo_Click()
1175 sbrStatus.Panels(1).Text = ""
1176 MsgBox ConnectInfo(con), vbOKOnly, "Connection Information"
1178 Private Sub cmdVersionInfo_Click()
1179 sbrStatus.Panels(1).Text = ""
1180 MsgBox VersionInfo(con), vbOKOnly, "Versions Information"
1182 Private Sub cmdExit_Click()
1183 chkAutoCommit.Value = 1
1184 Set hflxRecords.DataSource = Nothing
1185 Set DataGridSQL.DataSource = Nothing
1190 Private Sub cmdSample_Click()
1191 On Error GoTo cmdSample_Error
1192 sbrStatus.Panels(1).Text = "Creating the sample database, please wait..."
1194 sbrStatus.Panels(1).Text = "Create the sample database is done."
1195 If wShowInstructions = vbYes Then
1196 MsgBox "The sample database has been created!" & vbCr & _
1197 "You may now choose one of the connections.", _
1198 vbOKOnly, "Instruction"
1203 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1204 If wShowInstructions = vbYes Then
1205 MsgBox "Create sample database failed!" & vbCr & _
1206 Err.Description & vbCr & _
1207 "Please correct the problem and try again.", _
1208 vbOKOnly + vbCritical, "Instruction"
1210 Resume cmdSample_Exit
1212 Private Sub cmdSQLConnection_Click()
1213 On Error GoTo cmdSQLConnection_Error
1214 DataGridSQL.ClearFields
1215 Set rst = ExecuteSQLConnect(txtSQL, strMsgText, con)
1216 Set DataGridSQL.DataSource = rst
1217 sbrStatus.Panels(1).Text = strMsgText
1218 cmdSQLConnection_Exit:
1220 cmdSQLConnection_Error:
1221 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1222 Resume cmdSQLConnection_Exit
1224 Private Sub cmdSQLCommand_Click()
1225 On Error GoTo cmdSQLCommand_Error
1226 DataGridSQL.ClearFields
1227 Set rst = ExecuteSQLCommand(txtSQL, strMsgText, con)
1228 Set DataGridSQL.DataSource = rst
1229 sbrStatus.Panels(1).Text = strMsgText
1232 cmdSQLCommand_Error:
1233 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1234 Resume cmdSQLCommand_Exit
1236 Private Sub cmdSQLRecordset_Click()
1237 On Error GoTo cmdSQLRecordset_Error
1238 DataGridSQL.ClearFields
1239 Set rst = ExecuteSQLRecordset(txtSQL, strMsgText, con)
1240 Set DataGridSQL.DataSource = rst
1241 DataGridSQL.SetFocus
1242 sbrStatus.Panels(1).Text = strMsgText
1243 cmdSQLRecordset_Exit:
1245 cmdSQLRecordset_Error:
1246 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1247 Resume cmdSQLRecordset_Exit
1249 Private Sub DataGridSQL_Error(ByVal DataError As Integer, Response As Integer)
1250 If wShowInstructions = vbYes Then
1252 "If errors keep happening," & vbCr & _
1253 "You may press [Disconnect] to clear errors.", _
1254 vbOKOnly, "Instruction"
1256 sbrStatus.Panels(1).Text = "Press [Disconnect] to clear continuous errors."
1258 Private Sub cmdSQLSamples_Click(Index As Integer)
1261 txtSQL.Text = "SELECT * FROM employee"
1263 txtSQL.Text = "SELECT firstnme, job, hiredate" & vbCrLf & _
1264 "FROM employee" & vbCrLf & _
1265 "WHERE workdept = 'D11'" & vbCrLf & _
1268 txtSQL.Text = "SELECT firstnme, job, salary + comm AS pay" & vbCrLf & _
1269 "FROM employee" & vbCrLf & _
1270 "WHERE (salary + comm) < 25000" & vbCrLf & _
1273 txtSQL.Text = "SELECT workdept," & vbCrLf & _
1274 " MAX(salary) AS maximum," & vbCrLf & _
1275 " MIN(salary) As minimum" & vbCrLf & _
1276 "FROM employee GROUP BY workdept ORDER BY workdept"
1280 Private Sub cmdSQLSamples_GotFocus(Index As Integer)
1281 Set DataGridSQL.DataSource = Nothing
1282 sbrStatus.Panels(1).Text = ""
1284 Private Sub chkAutoCommit_Click()
1285 On Error GoTo chkAutoCommit_Error
1286 If chkAutoCommit.Value = 0 Then
1288 cmdCommit.Enabled = True
1289 cmdRollback.Enabled = True
1290 sbrStatus.Panels(1).Text = "AutoCommit mode is OFF."
1292 strMsgText = "Commit all previous changes (if any)?"
1293 If MsgBox(strMsgText, vbYesNo, "Turn Autocommit ON") = vbYes Then
1298 cmdCommit.Enabled = False
1299 cmdRollback.Enabled = False
1300 sbrStatus.Panels(1).Text = "AutoCommit mode is ON."
1305 chkAutoCommit_Error:
1306 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1307 Resume chkAutoCommit_Exit
1309 Private Sub cmdCommit_Click()
1310 On Error GoTo cmdCommit_Error
1311 If chkAutoCommit.Value = 0 Then
1315 sbrStatus.Panels(1).Text = "Commit transactions succeeded."
1320 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1321 Resume cmdCommit_Exit
1323 Private Sub cmdRollback_Click()
1324 On Error GoTo cmdRollback_Error
1325 If chkAutoCommit.Value = 0 Then
1329 sbrStatus.Panels(1).Text = "Rollback transactions succeeded."
1334 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1335 Resume cmdRollback_Exit
1337 Private Sub RefreshDataGridSQL()
1338 If Not DataGridSQL.DataSource Is Nothing Then
1339 Set DataGridSQL.DataSource = Nothing
1341 Set DataGridSQL.DataSource = rst
1344 Private Sub cmdHierarchy_Click()
1346 Set hflxRecords.DataSource = ExecuteHSQL(strMsgText, con)
1347 sbrStatus.Panels(1).Text = strMsgText
1349 Private Sub cmdRefresh_Click()
1350 On Error GoTo cmdRefresh_Error
1351 GetLOB con, AdodcLob
1353 txtClob.DataField = "RESUME"
1354 Set txtClob.DataSource = AdodcLob
1355 picBlob.DataField = "PICTURE"
1356 Set picBlob.DataSource = AdodcLob
1357 txtEmpno.DataField = "EMPNO"
1358 Set txtEmpno.DataSource = AdodcLob
1359 txtLastname.DataField = "LASTNAME"
1360 Set txtLastname.DataSource = AdodcLob
1361 txtFirstname.DataField = "FIRSTNME"
1362 Set txtFirstname.DataSource = AdodcLob
1363 cmdBLOB.Enabled = True
1364 cmdCLOB.Enabled = True
1365 AdodcLob.Enabled = True
1369 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1370 AdodcLob.Enabled = False
1371 cmdBLOB.Enabled = False
1372 cmdCLOB.Enabled = False
1373 Resume cmdRefresh_Exit
1375 Private Sub cmdBLOB_Click()
1376 picBlob.Visible = True
1378 Private Sub cmdCLOB_Click()
1379 picBlob.Visible = False
1381 Private Sub AdodcLob_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
1382 AdodcLob.Caption = AdodcLob.Recordset.AbsolutePosition
1384 Private Sub CheckAvailableStoredProcedures()
1385 Dim optStoredProcedure As Variant
1386 Dim proToken As ADOX.Procedure
1387 Dim pros As ADOX.Procedures
1388 Set pros = GetProcedures(con)
1389 For Each optStoredProcedure In optStoredProcedures
1390 optStoredProcedure.Enabled = False
1391 optStoredProcedure.Value = False
1392 cmdShowSecondRS.Visible = False
1393 cmdSPCall.Enabled = False
1395 For Each proToken In pros
1396 Select Case proToken.Name
1398 optStoredProcedures(0).Enabled = True
1400 optStoredProcedures(1).Enabled = True
1402 optStoredProcedures(2).Enabled = True
1404 optStoredProcedures(3).Enabled = True
1405 Case "ALL_DATA_TYPES"
1406 optStoredProcedures(4).Enabled = True
1408 optStoredProcedures(5).Enabled = True
1409 Case "ONE_RESULT_SET"
1410 optStoredProcedures(6).Enabled = True
1411 Case "TWO_RESULT_SETS"
1412 optStoredProcedures(7).Enabled = True
1414 optStoredProcedures(8).Enabled = True
1415 Case "DB2SQL_EXAMPLE"
1416 optStoredProcedures(9).Enabled = True
1417 Case "DBINFO_EXAMPLE"
1418 optStoredProcedures(10).Enabled = True
1420 optStoredProcedures(11).Enabled = True
1424 For Each optStoredProcedure In optStoredProcedures
1425 If optStoredProcedure.Enabled Then
1426 cmdSPCall.Enabled = True
1431 Set proToken = Nothing
1433 Private Sub optStoredProcedures_Click(Index As Integer)
1434 sbrStatus.Panels(1).Text = ""
1435 txtSPResult.Text = ""
1436 If DataGridSP.Visible Then
1437 DataGridSP.Visible = False
1438 Set DataGridSP.DataSource = Nothing
1439 DataGridSP.ClearFields
1440 cmdShowSecondRS.Visible = False
1444 Private Sub cmdSPCall_Click()
1445 Dim optStoredProcedure As Variant
1446 Dim strParam As String
1447 On Error GoTo cmdSPCall_Error
1448 For Each optStoredProcedure In optStoredProcedures
1449 If optStoredProcedure.Value = True Then
1453 If IsObject(optStoredProcedure) Then
1454 sbrStatus.Panels(1).Text = ""
1455 txtSPResult.Text = ""
1456 DataGridSP.Visible = False
1458 sbrStatus.Panels(1).Text = "ERROR: No stored procedure selected."
1461 Select Case optStoredProcedure.Caption
1463 txtSPResult.Text = _
1464 "Stored procedures are implemented in LANGUAGE " & _
1465 CallSP_OUT_LANGUAGE(con)
1471 txtSPResult.Text = _
1472 "Stored Procedure OUT_PARAM calculated median was " & _
1473 CallSP_OUT_PARAM(con)
1476 Case "ALL_DATA_TYPES"
1479 txtSPResult.Text = _
1480 "Stored Procedure DECIMAL_TYPE returned value was " & _
1481 CallSP_DECIMAL_TYPE(con)
1483 txtSPResult.Text = _
1484 "Resume section returned from calling CLOB_EXTRACT:" & _
1485 vbCrLf & vbCrLf & CallSP_CLOB_EXTRACT(con)
1486 Case "ONE_RESULT_SET"
1487 Set DataGridSP.DataSource = CallSP_ONE_RESULT_SET(con)
1488 DataGridSP.Visible = True
1489 Case "TWO_RESULT_SETS"
1490 Set rst = CallSP_TWO_RESULT_SETS(con)
1491 Set DataGridSP.DataSource = rst
1492 DataGridSP.Visible = True
1493 cmdShowSecondRS.Visible = True
1494 cmdShowSecondRS.Enabled = True
1495 cmdShowSecondRS.SetFocus
1496 Case "DB2SQL_EXAMPLE"
1498 txtSPResult.Text = _
1499 "Stored Procedure DB2SQL_EXAMPLE returned value was " & _
1500 CallSP_DB2SQL_EXAMPLE(con, strParam) & _
1501 vbCrLf & "for the job of " & strParam & "."
1502 Case "DBINFO_EXAMPLE"
1505 strParam = "DESIGNER"
1506 txtSPResult.Text = _
1507 "Stored Procedure MAIN_EXAMPLE returned value was " & _
1508 CallSP_DB2SQL_EXAMPLE(con, strParam) & _
1509 vbCrLf & "for the job of " & strParam & "."
1511 sbrStatus.Panels(1).Text = _
1512 "Stored Procedure " & optStoredProcedure.Caption & _
1513 " was called successfully."
1517 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1518 Resume cmdSPCall_Exit
1520 Private Sub cmdShowSecondRS_Click()
1521 Set DataGridSP.DataSource = rst.NextRecordset
1522 cmdShowSecondRS.Enabled = False
1525 Private Sub CallInParameters()
1526 Dim strSQL As String
1527 strSQL = "SELECT SUM(salary) FROM employee WHERE workdept = 'E11'"
1528 Set rst = ExecuteSQLCommand(strSQL, strMsgText, con)
1529 txtSPResult.Text = "Before calling IN_PARAMS, " & vbCrLf & _
1530 "Sum of salaries for dept. E11 = " & _
1531 rst.Fields(0).Value & vbCrLf & vbCrLf
1532 CallSP_IN_PARAMS con
1533 txtSPResult.Text = txtSPResult.Text & _
1534 "SAMPLE Stored Procedure IN_PARAMS was called." & vbCrLf & vbCrLf
1535 Set rst = ExecuteSQLCommand(strSQL, strMsgText, con)
1536 txtSPResult.Text = txtSPResult.Text & _
1537 "After calling IN_PARAMS, " & vbCrLf & _
1538 "Sum of salaries for dept. E11 = " & _
1539 rst.Fields(0).Value & vbCrLf
1543 Private Sub CallInOutParameter()
1544 Dim dblMedian As Double
1545 txtSPResult.Text = "Call OUT_PARAM to get the median."
1546 dblMedian = CallSP_OUT_PARAM(con)
1547 txtSPResult.Text = txtSPResult.Text & vbCrLf & _
1548 "Stored procedure returned successfully." & vbCrLf
1549 txtSPResult.Text = txtSPResult.Text & vbCrLf & _
1550 "Call INOUT_PARAM with the result just got."
1551 txtSPResult.Text = txtSPResult.Text & vbCrLf & _
1552 "New median returned from INOUT_PARAM = " & _
1553 CallSP_INOUT_PARAM(con, dblMedian)
1555 Private Sub CallAllDataTypes()
1556 Dim pms As ADODB.Parameters
1558 .Text = "Call ALL_DATA_TYPES to get all types of data."
1559 Set pms = CallSP_ALL_DATA_TYPES(con)
1560 .Text = .Text & vbCrLf & "Stored procedure returned successfully."
1561 .Text = .Text & vbCrLf & _
1562 vbCrLf & "Value of SMALLINT = " & pms("SMALL").Value & _
1563 vbCrLf & "Value of INTEGER = " & pms("INTIN").Value & _
1564 vbCrLf & "Value of BIGINT = " & pms("BIGIN").Value & _
1565 vbCrLf & "Value of REAL = " & pms("REALIN").Value & _
1566 vbCrLf & "Value of DOUBLE = " & pms("DOUBLEIN").Value & _
1567 vbCrLf & "Value of CHAR(1) = " & pms("CHAROUT").Value & _
1568 vbCrLf & "Value of CHAR(15) = " & pms("CHARSOUT").Value & _
1569 vbCrLf & "Value of VARCHAR(12) = " & pms("VARCHAROUT").Value & _
1570 vbCrLf & "Value of DATE = " & pms("DATEOUT").Value & _
1571 vbCrLf & "Value of TIME = " & TimeValue(pms("TIMEOUT").Value)
1575 Private Sub CallDbInfo()
1576 Dim pms As ADODB.Parameters
1577 Dim strJob As String
1578 txtSPResult.Text = "CALL stored procedure named DBINFO_EXAMPLE."
1580 Set pms = CallSP_DBINFO_EXAMPLE(con, strJob)
1581 txtSPResult.Text = txtSPResult.Text & vbCrLf & _
1582 "Stored procedure returned successfully with SQLCODE = " & _
1583 pms("ERRORCODE").Value
1584 txtSPResult.Text = txtSPResult.Text & vbCrLf & _
1585 "Average salary for job " & strJob & " = " & pms("SALARY").Value
1586 txtSPResult.Text = txtSPResult.Text & vbCrLf & _
1587 "Database name from OUT parameter = " & Trim$(pms("DBNAME").Value)
1588 txtSPResult.Text = txtSPResult.Text & vbCrLf & _
1589 "Database version from OUT parameter = " & pms("DBVERSION").Value
1592 Private Sub cmdUDFs_Click(Index As Integer)
1593 On Error GoTo cmdUDFs_Error
1594 sbrStatus.Panels(1).Text = ""
1596 hflxGridUDF.ClearStructure
1597 Select Case cmdUDFs(Index).Caption
1599 hflxGridUDF.ColWidth(3) = 2000
1600 Set hflxGridUDF.DataSource = CallUDFScalarUDF(strMsgText, con)
1601 Case "ClobScalarUDF"
1602 Set hflxGridUDF.DataSource = CallUDFClobScalarUDF(strMsgText, con)
1603 Case "ScratchpadScUDF"
1604 Set hflxGridUDF.DataSource = CallUDFScratchpadScUDF(strMsgText, con)
1605 Case "ScUDFReturningErr"
1606 Set hflxGridUDF.DataSource = CallUDFScUDFReturningErr(strMsgText, con)
1607 txtUDF.Text = strMsgText
1608 Err.Raise vbObjectError, , "See display area for detail."
1609 Case "SourcedColumnUDF"
1610 Set hflxGridUDF.DataSource = CallUDFSourcedColUDF(strMsgText, con)
1612 Set hflxGridUDF.DataSource = CallUDFTableUDF(strMsgText, con)
1615 txtUDF.Text = strMsgText
1616 sbrStatus.Panels(1).Text = _
1617 "Calling UDF " & cmdUDFs(Index).Caption & " was done."
1621 sbrStatus.Panels(1).Text = "ERROR: " & Err.Description
1624 Private Sub Form_Load()
1626 wShowInstructions = vbYes
1627 wShowInstructions = MsgBox("Would you like to have instructions?", _
1628 vbYesNo, "Welcome to the DB2 Visual Basic samples")
1630 Private Sub Form_Activate()
1631 If wShowInstructions = vbYes Then
1633 "Thank you for using instructions in this demonstration program!" & vbCr & vbCr & _
1634 "- Status messages are shown at the bottom of the working window;" & vbCr & _
1635 "- Buttons unavailable are being grayed out;" & vbCr & _
1636 "- SAMPLE database must be created if it doesn't exist;" & vbCr & _
1637 "- [Exit] button can be pressed at anytime to quit the program." & vbCr & vbCr & _
1638 "You may now choose one of the connections to begin the demonstraton.", _
1639 vbOKOnly, "Instruction"
1642 Private Sub tabMain_Click(intPreviousTab As Integer)
1643 Select Case tabMain.TabCaption(intPreviousTab)
1645 chkAutoCommit.Value = 1
1647 Set DataGridSQL.DataSource = Nothing
1648 DataGridSQL.ClearFields
1649 Case "Hierarchical Data"
1650 Set hflxRecords.DataSource = Nothing
1655 txtLastname.Text = ""
1656 txtFirstname.Text = ""
1657 AdodcLob.Caption = ""
1658 AdodcLob.Enabled = False
1659 cmdBLOB.Enabled = False
1660 cmdCLOB.Enabled = False
1661 picBlob.Visible = False
1662 Case "Store Procedures"
1664 Set DataGridSP.DataSource = Nothing
1665 DataGridSP.Visible = False
1666 DataGridSP.ClearFields
1667 cmdShowSecondRS.Visible = False
1668 txtSPResult.Text = ""
1674 sbrStatus.Panels(1).Text = ""
1676 Private Sub tabMain_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
1677 If wShowInstructions = vbYes Then
1678 If con Is Nothing Then 'no connection established
1680 "All funcitonal features require a valid connection.", _
1681 vbOKOnly + vbExclamation, "Instruction"
1683 Select Case tabMain.Caption
1686 "Please type a SQL statement into the text box, or," & vbCr & _
1687 "choose a preset one from the small Sample buttons, then," & vbCr & _
1688 "press one of the [Execute SQL] buttons to get the results." & vbCr & _
1689 "AutoCommit checkbox can be used to change the autocommit mode." & vbCr & vbCr & _
1690 "For more about the connection, command, and recordset objects," & vbCr & _
1691 "see the source code in the apExeSQL.bas module." & vbCr & vbCr & _
1693 "- The sample SQL statements can be edited." & vbCr & _
1694 "- Recordset results may be editable depending on the SQL statement issued.", _
1695 vbOKOnly, "Instruction"
1696 Case "Hierarchical Data"
1697 If InStr(con.Provider, "MSDataShape") Then
1699 "Please press the [Display] button to display hierarchical result.", _
1700 vbOKOnly, "Instruction"
1703 "Hierarchical Data is only available for a" & vbCr & _
1704 "valid connection with DataShape.", _
1705 vbOKOnly + vbExclamation, "Instruction"
1709 "After pressing the [Refresh Data] button;" & vbCr & _
1710 "Use arrow keys to manipulate results;" & vbCr & _
1711 "Press [Show Resume] button to display CLOBs;" & vbCr & _
1712 "Press [Show Picture] button to display BLOBs.", _
1713 vbOKOnly, "Instruction"
1714 Case "Store Procedures"
1716 "Choose an available stored procedure, then," & vbCr & _
1717 "press the [Call] button to get the results." & vbCr & vbCr & _
1718 "Note: To make them available, you first have to create and catalog" & vbCr & _
1719 "the stored procedures in the spserver stored procedure library.", _
1720 vbOKOnly, "Instruction"
1723 "Please choose one of the UDF buttons to show the usage.", _
1724 vbOKOnly, "Instruction"