Results 1 to 2 of 2

Thread: Funny results from SQL command used in VBScript

  1. #1
    Join Date
    Apr 2003
    Posts
    1

    Unhappy Funny results from SQL command used in VBScript

    Hi Everyone,

    I am currently writing a VBScript that will help us update our asset tracking database as we deploy workstations. Here is the statement I am having trouble with:

    objConnection.Execute "SELECT Department FROM tblEmployee WHERE USERID='"&Username&"'",Department

    My connection to the database works and I have used this command in SQL Server's query analyzer and it works but when I run it from the VBScript, I invetiably get a Department Value of -1. Can anybody point me in the right direction? thanks!

  2. #2
    Join Date
    Jun 2003
    Posts
    3
    Try doing this instead:

    dim objCn, objRs, strDepartment
    set objCn = CreateObject("ADODB.Connection")
    set objRs = CreateObject("ADODB.Recordset")

    'Open your connection...
    objCn.Open "DSN=myDSN;"

    objRs.Open "SELECT Department FROM tblEmployee WHERE USERID='" & UserNAme & "'", objCN

    if NOT objRs.EOF
    strDepartment = objRs("Department")
    else
    strDepartment = "*** NOT FOUND ***"
    end if

    objRs.Close
    objCn.Close

    set objRs = Nothing
    set objCn = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •