VBScript to return count from Oracle Database

Hi,

I have a VBScript that connects to an Oracle database and returns a count from a table.  I want to use the returned value as a conditional statement, but get the error message Type mismatch.  I can display the value correctly but can not seem to use it in the If statement.  Is it possible that the count is returning as a string variable, if so how do I convert it to use in the condition

Code is :-

'Create object to open log file and then open the file
Set objFSOLog = CreateObject("Scripting.FileSystemObject")
Set LogFile = objFSOLog.OpenTextFile(strFullLogPath, ForAppending, True)

'============================================================================================

strSQL = "SELECT COUNT(1) from ci_bill"
Set adoConnection = CreateObject("ADODB.Connection")

'============================================================================================

strConnect ="Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=172.)(PORT=15))" & _
"(CONNECT_DATA=(SERVICE_NAME=niedev))); uid=;pwd=;"

'============================================================================================

adoConnection.Open strConnect
Set adoRecordset = CreateObject("ADODB.Recordset")
adoRecordset.ActiveConnection = adoConnection
' Run the query and create resulting recordset.
adoRecordset.Source = strSQL
adoRecordset.Open

' Enumerate the recordset.
strField1 = adoRecordset.Fields(0).Value
If strField1=0 Then
   msgbox "Count is non-zero"
end If

Thanks in advance

Heather
HRMortonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jinesh KamdarCommented:
I believe ur variable strField is a string, but you're trying to compare it directly with a number. Either get the return value into a number or use this - If strField1='0' Then
0
Jinesh KamdarCommented:
I meant - If strField1 = "0" Then
0
philly_teeCommented:
Hi Heather,

I assume your problem is in

strField1 = adoRecordset.Fields(0).Value
If strField1=0 Then
   msgbox "Count is non-zero"
end If

It is likely that the result will be a string,  try

If CInt(strField1) = 0 Then

Of course, if it's possible the value will be higher than the max for an integer, you can use a double instead, use CDbl instead of CInt.

Regards

Philip
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

HRMortonAuthor Commented:
Thanks for the quick response guys, solution worked perfectly.  Much appreciated.
0
HRMortonAuthor Commented:
Thanks for the help
0
Jinesh KamdarCommented:
Which solution worked?
0
HRMortonAuthor Commented:
Thanks for the help.  Used the CDbl, as suggested the CInt was not large enough for what I needed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.