| 
 Siebel VB Language Reference > Methods Reference for Siebel VB > ODBC Methods > 
ODBC Run Query and Get Results Method
 
The ODBC Run Query And Get Results method is a Siebel VB method that opens a connection to a data source, runs an SQL statement, returns the result, and then closes the connection. It returns a variant that includes one of the following values: 
- Positive number. The request is successful. The number identifies the number of results that this method returned or the number of rows affected. Other SQL statements return 0.
 - Negative error code. An error occurred. It cannot complete the connection, the query is not valid, or another error condition occurred.
  
Format
SQLRequest(connectString, query, outputString[, prompt][, columnNames], ref()) 
The following table describes the arguments that you can use with this method. 
     | 
     | 
 
    connectString  | 
    A string or string variable that specifies the data source. For more information on the connect string, see ODBC Open Connection Method.  | 
 
    query  | 
    An SQL query statement that this method runs.  | 
 
    outputString  | 
    A string variable that holds the completed connection string.  | 
 
    prompt  | 
    An integer that specifies when to display the driver dialog box. For more information about using the prompt argument, see ODBC Open Connection Method.  | 
 
    columnNames  | 
    An integer. If columnNames is not zero, then it returns column names in the first row of the array that the ref argument identifies. If you do not include the columnNames argument, then the default value is 0.  | 
 
    ref  | 
    An array of type variant that holds the results of the action you request. It must be an array even if it includes only one dimension with one element.  | 
 
 
 
 Example
The following example uses the ODBC Run Query And Get Results method: Function WebApplet_PreInvokeMethod (MethodName As String) As Integer    If MethodName = "queryExtSys" Then 
      ' The following opens the datasource SVBTESTW and       ' runs the query specified by query and returns the       ' results in destination. 
      Dim errors(1 To 10, 1 To 3) As Variant       Dim destination(1 To 50, 1 To 125)  As Variant       Dim prompt As Integer       Dim outputStr As String       Dim retCode As Integer 
      ' In the event of a connection error, do not display a       ' dialog box, return an error       prompt = 4 
      ' SQL Statement to submit. In this example we'll perform a       ' simple select       query = "SELECT * FROM authors" 
      ' Invoke the SQLRequest function to submit the SQL, run the       ' query and return a result set.       retCode = SQLRequest("DSN=SVBTESTW;UID=sa;PWD=sa", _                query, outputStr, prompt, 0, destination()) 
      ' If retCode < 0,  an error has occurred. Retrieve the first       ' error returned in the array and display to the user.       If retCode < 0 Then          SQLError destination := errors          errCounter = 1 
         While errors(errCounter,1) <> 0             TheApplication.RaiseErrorText "Error  " & _             "  ODBC error: " & destination(errCounter,1) & _             "  Numeric code = " & destination(errCounter,2) & _             "  Error Text = " & destination(errCounter,3) 
            errCounter = errCounter + 1          Wend       Else          ' do some processing of the results       End If 
      WebApplet_PreInvokeMethod = CancelOperation    Else       WebApplet_PreInvokeMethod = ContinueOperation    End If 
End Function 
 |