Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieving data from database table

Status
Not open for further replies.

rockbold

Technical User
Dec 20, 2004
11
US
hello all
I am working on a database application that uses VB6 at frontend and oracle9i at the backend. I know how to bind tables fields to the controls on the form and retrieve data using adodc control, but I need to know a way to retrieve information from database table without having to bind it to any control on the form. Preferrably just by running a query and storing the result into a variable. is there a way to do that? your help will be appreciated.
rockbold
 
This code runs a stored procedure in Oracle 9i
it may do what you need
Code:
Private Sub Command2_Click()

Dim Oracon As ADODB.Connection
Dim recset As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim param1 As New ADODB.Parameter
Dim param2 As New ADODB.Parameter
Dim objErr As ADODB.Error
Dim Message, Title, Default, DeptValue

Message = "Enter a department number (10, 20, or 30)"
Title = "Choose a Department"
Default = "30"

On Error GoTo err_test

DeptValue = InputBox(Message, Title, Default)
If DeptValue = "" Then Exit Sub
If DeptValue < 10 Or DeptValue > 30 Then DeptValue = 30
  
Set Oracon = CreateObject("ADODB.Connection")
Oracon.ConnectionString = "Provider=OraOLEDB.Oracle;" & _
                          "Data Source=db816;" & _
                          "User ID=scott;" & _
                          "Password=tiger;" & _
                          "PLSQLRSet=1;"
Oracon.Open

Set cmd = New ADODB.Command
Set cmd.ActiveConnection = Oracon

Set param1 = cmd.CreateParameter("param1", adSmallInt, adParamInput, , DeptValue)
cmd.Parameters.Append param1
Set param2 = cmd.CreateParameter("param2", adSmallInt, adParamOutput)
cmd.Parameters.Append param2

cmd.CommandText = "{CALL Employees.GetEmpRecords(?, ?)}"
Set recset = cmd.Execute
Do While Not recset.EOF
   MsgBox "Number: " & recset.Fields("empno").Value & "  Name: " & _
   recset.Fields("ename").Value & "  Dept: " & recset.Fields("deptno").Value
   recset.MoveNext
Loop
  
Exit Sub
   
err_test:
  MsgBox Error$
  For Each objErr In Oracon.Errors
    MsgBox objErr.Description
  Next
  Oracon.Errors.Clear
  Resume Next
End Sub

DougP, MCP, A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top