Jump to content

_sql.au3 - No Records


Recommended Posts

Hello all, I have been using Autoit for a couple years, and over time have been learning as I go. Recently I have expanded into using SQL. At my work we have a million little queries that we use all the time. We use SQL 2000, so I found the _sql.au3 which has done wonders.

I have all my queries running nicely. However there is one issue that I have not been able to see the solution for even as I have searched the forum allot for. When I run a select statement, and there are no results, it doesn't display anything, but if there is results, it displays it in 2d array. Is there a piece of code that I can add that if there are no results it will display a msg box or something. Here is some of my code.

Let me know if I can provide any other information.

#include <array.au3>

#include <_sql.au3>

_SQLRegisterErrorHandler();register the error handler to prevent hard crash on COM error

$listname = 'TDCS08'

$con = _SQLStartup()

If @error then Msgbox(0,"Error","Error starting ADODB.Connection")

_SQLConnect(-1,"toronto4","gcti_500",'Username','password')

if @Error then Msgbox(0,"",$SQLErr)

$Query = "select top 20 * from " & $ListName

$data = _SQLExecute(-1,$Query)

If Not @error then

$aData = _SQLGetData2D($data)

_arrayDisplay($aData)

Else

Msgbox(0,"",$SQLErr)

EndIf

_SQLClose()

Link to comment
Share on other sites

Hi

I've updated the _sql.au3 file

See here http://www.autoitscript.com/forum/index.php?showtopic=51952

Change this part of your script as follows

$aData = _SQLGetData2D($data)
If NOT @error then 
  _arrayDisplay($aData)
Else
  Msgbox(0,"Error",$SQLErr)
Endif

If there a Zero records @error will be set and $SQLErr will be set to "Query has no data"

Chris

Edited by ChrisL
Link to comment
Share on other sites

Nice, thanks allot Chris. This works like a charm.

Hey one thing, are you from peterborough ontario canada? If so thats weird because that is where I grew up. ^_^

Your welcome! I live in Peterborough in England, just a little bit further away ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...