Re: error no record



THANK YOU .... IT'S PERFECT

"Roland Hall" <nobody@nowhere> ha scritto nel messaggio
news:OhTlU$c5FHA.1416@xxxxxxxxxxxxxxxxxxxxxxx
> "Simone" wrote in message news:u9AYdjc5FHA.3636@xxxxxxxxxxxxxxxxxxxxxxx
> :I made a script, that connect to a sql server db, and made a query. The
> : query's result became in a message box.
> : This is the script:
> :
> : 'Read the environment variable USERNAME on the client
> : Dim oShell
> : Dim UserName
> : Set oShell = Wscript.CreateObject("Wscript.Shell")
> : UserName = oShell.ExpandEnvironmentStrings("%USERNAME%")
> : 'Open the database connection
> : dim objConn
> : Set objConn = CreateObject("ADODB.Connection")
> : objConn.Open "Driver={SQL Server};" & _
> : "Server=10.10.85.11;" & _
> : "Address=10.10.85.11,1433;" & _
> : "Network=DBMSSOCN;" & _
> : "Database=pluto;" & _
> : "Trusted_Connection=yes;"
> :
> : 'Create the recordset object
> : Set objRS = CreateObject("ADODB.Recordset")
> : 'Define the SQL query
> : strComplexSQLQuery = "SELECT balance FROM disney WHERE name = 'pippo'
> ORDER
> : BY id DESC"
> : 'Open the recordset
> : objRS.Open strComplexSQLQuery, objConn
> : 'Take the customer and sales person names from the recordset
> : Credito = objRS(0)
> : 'strSalesPersonName = objRS(1)
> : 'Tidy up the objects
> : objRS.Close
> : objConn.Close
> : Set objRS = Nothing
> : Set objConn = Nothing
> : 'Output the data
> : MsgBox(UserName & " Il tuo credito residuo è " & Credito)
> :
> : Now the question: if the script doesn't find a record, it give me a
> Error
> : with code 800A0BCD.
> : But I want a message box that say "Record not present".
>
> Try changing this part:
>
> Credito = objRS(0)
> 'strSalesPersonName = objRS(1)
> 'Tidy up the objects
> objRS.Close
> objConn.Close
> Set objRS = Nothing
> Set objConn = Nothing
> 'Output the data
> MsgBox(UserName & " Il tuo credito residuo è " & Credito)
>
> to:
>
> if not (objRS.BOF or objRS.EOF) then
> Credito = objRS(0)
> 'strSalesPersonName = objRS(1)
>
> 'Tidy up the objects
> objRS.Close : Set objRS = Nothing
> objConn.Close : Set objConn = Nothing
>
> 'Output the data
> MsgBox(UserName & " Il tuo credito residuo è " & Credito)
> else
> 'Tidy up the objects
> objRS.Close : Set objRS = Nothing
> objConn.Close : Set objConn = Nothing
>
> 'Output the data
> MsgBox("Record not present")
> end if
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation -
> http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>


.



Relevant Pages

  • Re: error no record
    ... : Dim UserName ... : 'Create the recordset object ... Set objRS = Nothing ... Set objConn = Nothing ...
    (microsoft.public.scripting.vbscript)
  • Database add record
    ... My application requires that I accept form data from another ... site using POST method to add records to an Access db. ... Set objRS = Server.Create.Object ... Set objConn = Server.CreateObject ...
    (microsoft.public.frontpage.client)
  • RE: How to convert Local time on a computer, into a record in a Access
    ... Set objConn = CreateObject ... Set objRS = CreateObject ... Set colRetrievedItem = objWMIService.ExecQuery _ ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: VBSCRIPT with SQL help
    ... Set objConn = CreateObject ... Set objRS = CreateObject ... objRS.Open strSQL, objConn, 3, 3 ... | modified to capture event logs, I now want to modify it again to caputer ...
    (microsoft.public.scripting.vbscript)