Sie sind auf Seite 1von 7

CONNECTING DB2 TO VB6.

CONNECTING DB2 TO VB6.0

CONNECTING DB2 TO VB6.0

Private Sub Command1_Click() 'Initialize objects On Error GoTo Command3_ErrorProc: Dim adoConn As New ADODB.Connection Dim adoCmd As New ADODB.Command Dim objErr As ADODB.Error Dim adoParm As ADODB.Parameter Dim adoRs As ADODB.Recordset Dim RecordsAffected As Long Dim SqlSent As String Dim i As Integer List1.Clear

CONNECTING DB2 TO VB6.0

'Set cursor location to client, so that record count does not return -1 'See Microsoft Knowledge Base article Q194973 for discussion adoConn.CursorLocation = adUseClient Me.MousePointer = 11

'Select statement with WHERE criteria on first column 'Modify this statement if you are not using the provided sample table SqlSent = "SELECT * FROM ROHITDB2.TAB WHERE T1 = 'Rohit'"

'Connection string using StarSQL DSN adoConn.Open "DSN=abc1;UID=ROHITDB2;PWD=rohit09"

'Command brproperties set<>adoCmd.Name = "TestParm" Set adoCmd.ActiveConnection = adoConn adoCmd.CommandText = SqlSent adoCmd.CommandType = adCmdText adoCmd.CommandTimeout = 15

'Parameter properties set Set adoParm = New ADODB.Parameter adoParm.Name = "MYPARM" adoParm.Type = adVarChar adoParm.Size = 10 adoCmd.Parameters.Append adoParm adoParm.Value = "TEST1"

CONNECTING DB2 TO VB6.0

'result set defined; execute SQL statement Set adoRs = adoCmd.Execute(RecordsAffected)

'Return first column of each record in result set to List box For i = 1 To adoRs.RecordCount Text1.Text = adoRs(0) List1.AddItem adoRs(0) adoRs.MoveNext Next

'Clear connection Set adoCmd = Nothing Set adoConn = Nothing Me.MousePointer = 0 Exit Sub

'Error handling Command3_ErrorProc: Me.MousePointer = 0 If Not adoCmd Is Nothing Then Set adoCmd = Nothing End If If Not adoConn Is Nothing Then Set adoConn = Nothing End If

CONNECTING DB2 TO VB6.0 MsgBox Err.Description

Exit Sub

End Sub

Private Sub Command2_Click()

'Initialize objects

Dim adoConn As New ADODB.Connection Dim adoCmd As New ADODB.Command Dim objErr As ADODB.Error Dim adoParm As ADODB.Parameter Dim adoRs As ADODB.Recordset Dim RecordsAffected As Long Dim SqlSent As String Dim i As Integer Dim k As Integer

List1.Clear

'Set cursor location to client, so that record count does not return -1 'See Microsoft Knowledge Base article Q194973 for discussion

CONNECTING DB2 TO VB6.0 adoConn.CursorLocation = adUseClient Me.MousePointer = 11

'Select statement with WHERE criteria on first column 'Modify this statement if you are not using the provided sample table SqlSent = "INSERT INTO ROHITDB2.TAB (T1 )VALUES('chaman')"

'Connection string using StarSQL DSN adoConn.Open "DSN=abc1;UID=Rohitdb2;PWD=rohit09"

'Command brproperties set<>adoCmd.Name = "TestParm" Set adoCmd.ActiveConnection = adoConn adoCmd.CommandText = SqlSent adoCmd.CommandType = adCmdText adoCmd.CommandTimeout = 15

'Parameter properties set Set adoParm = New ADODB.Parameter adoParm.Name = "MYPARM" adoParm.Type = adVarChar adoParm.Size = 10 adoCmd.Parameters.Append adoParm adoParm.Value = "TEST1"

Set adoRs = adoCmd.Execute(RecordsAffected) End Sub

Das könnte Ihnen auch gefallen