Windows Vista Forums

SQL Query in VBScript

  1. #1


    mcolson Guest

    SQL Query in VBScript

    I am using the following code to perform a SQL query and return a
    recordset I am getting the error "Arguments are of the wrong type,
    are out of acceptable range, or are in conflict with one another"
    This error occurs when I open the record set. What am I doing wrong?

    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    Const adUseClient = 3
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordset = CreateObject("ADODB.Recordset")
    objConnection.Open "DSN=ChartMES;"
    objRecordset.CursorLocation = adUseClient


    strQuery = "Use ChartMES " _
    & "SELECT EmployeeID " _
    & "FROM dbo.viewEmployeeTraining " _
    & "WHERE TrainingName = 'Inner / Outer Mass Spec Training' " _
    & "ORDER BY EmployeeID"

    ' Echo the query to the console to verify.
    Wscript.Echo strQuery

    'objRecordset.Source = strQuery
    objRecordset.Open strQuery, objConnection, adOpenStatic,
    adLockOpstimistic
    If objRecordset.EOF Then
    Wscript.Echo "Record cannot be found."
    Else
    Wscript.Echo "Record found."
    End If
    objRecordset.Close
    objRecordset.Close

      My System SpecsSystem Spec

  2. #2


    Tom Lavedas Guest

    Re: SQL Query in VBScript

    On Mar 9, 11:20*am, mcolson <mcolson1...@newsgroup> wrote:

    > I am using the following code to perform a SQL query and return a
    > recordset *I am getting the error "Arguments are of the wrong type,
    > are out of acceptable range, or are in conflict with one another"
    > This error occurs when I open the record set. *What am I doing wrong?
    >
    > Const adOpenStatic = 3
    > Const adLockOptimistic = 3
    > Const adUseClient = 3
    > Set objConnection = CreateObject("ADODB.Connection")
    > Set objRecordset = CreateObject("ADODB.Recordset")
    > objConnection.Open "DSN=ChartMES;"
    > objRecordset.CursorLocation = adUseClient
    >
    > strQuery = "Use ChartMES " _
    > * * * * & "SELECT EmployeeID " _
    > * * & "FROM dbo.viewEmployeeTraining " _
    > * * & "WHERE TrainingName = 'Inner / Outer Mass Spec Training' " _
    > * * & "ORDER BY EmployeeID"
    >
    > ' Echo the query to the console to verify.
    > Wscript.Echo strQuery
    >
    > 'objRecordset.Source = strQuery
    > objRecordset.Open strQuery, objConnection, adOpenStatic,
    > adLockOpstimistic
    > If objRecordset.EOF Then
    > * * Wscript.Echo "Record cannot be found."
    > Else
    > * * Wscript.Echo "Record found."
    > End If
    > objRecordset.Close
    > objRecordset.Close
    Is there a typo in this line ?...

    objRecordset.Open strQuery, objConnection, adOpenStatic,
    adLockOpstimistic

    I think you intended the last constant to be "adLockOptimistic" (no S
    after the P).
    _____________________
    Tom Lavedas

      My System SpecsSystem Spec

  3. #3


    mcolson Guest

    Re: SQL Query in VBScript

    On Mar 9, 10:53*am, Tom Lavedas <tglba...@newsgroup> wrote:

    > On Mar 9, 11:20*am, mcolson <mcolson1...@newsgroup> wrote:
    >
    >
    >

    > > I am using the following code to perform a SQL query and return a
    > > recordset *I am getting the error "Arguments are of the wrong type,
    > > are out of acceptable range, or are in conflict with one another"
    > > This error occurs when I open the record set. *What am I doing wrong?
    >

    > > Const adOpenStatic = 3
    > > Const adLockOptimistic = 3
    > > Const adUseClient = 3
    > > Set objConnection = CreateObject("ADODB.Connection")
    > > Set objRecordset = CreateObject("ADODB.Recordset")
    > > objConnection.Open "DSN=ChartMES;"
    > > objRecordset.CursorLocation = adUseClient
    >

    > > strQuery = "Use ChartMES " _
    > > * * * * & "SELECT EmployeeID " _
    > > * * & "FROM dbo.viewEmployeeTraining " _
    > > * * & "WHERE TrainingName = 'Inner / Outer Mass Spec Training' " _
    > > * * & "ORDER BY EmployeeID"
    >

    > > ' Echo the query to the console to verify.
    > > Wscript.Echo strQuery
    >

    > > 'objRecordset.Source = strQuery
    > > objRecordset.Open strQuery, objConnection, adOpenStatic,
    > > adLockOpstimistic
    > > If objRecordset.EOF Then
    > > * * Wscript.Echo "Record cannot be found."
    > > Else
    > > * * Wscript.Echo "Record found."
    > > End If
    > > objRecordset.Close
    > > objRecordset.Close
    >
    > Is there a typo in this line ?...
    >
    > objRecordset.Open strQuery, objConnection, adOpenStatic,
    > adLockOpstimistic
    >
    > I think you intended the last constant to be "adLockOptimistic" (no S
    > after the P).
    > _____________________
    > Tom Lavedas
    ahh jeez. Thanks

      My System SpecsSystem Spec


SQL Query in VBScript
Similar Threads
Thread Forum
Query printers in 2008 domain using vbscript or WMI VB Script
VBScript to Query WMI VB Script
execute mysql query using vbscript VB Script
SQL Query in VBScript VB Script
VBScript problem in running Stored Query VB Script