bartekd Posted April 21, 2009 Share Posted April 21, 2009 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 More sharing options...
Juvigy Posted April 21, 2009 Share Posted April 21, 2009 I am not 100% sure but i think it should return "null" if no entries are found so just check: if $data=="null" then Msgbox() Link to comment Share on other sites More sharing options...
bartekd Posted April 21, 2009 Author Share Posted April 21, 2009 Thanks for the suggestion, but that doesn't seem to work. Can anyone else think of something? Link to comment Share on other sites More sharing options...
Juvigy Posted April 21, 2009 Share Posted April 21, 2009 Maybe it is returning blank string - ""? I dont have _sql include file. What does _SQLExecute return if no records are found?? Link to comment Share on other sites More sharing options...
ChrisL Posted April 21, 2009 Share Posted April 21, 2009 (edited) HiI've updated the _sql.au3 file See here http://www.autoitscript.com/forum/index.php?showtopic=51952Change this part of your script as follows$aData = _SQLGetData2D($data) If NOT @error then _arrayDisplay($aData) Else Msgbox(0,"Error",$SQLErr) EndifIf there a Zero records @error will be set and $SQLErr will be set to "Query has no data"Chris Edited April 21, 2009 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
bartekd Posted April 22, 2009 Author Share Posted April 22, 2009 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. Link to comment Share on other sites More sharing options...
ChrisL Posted April 22, 2009 Share Posted April 22, 2009 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 [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now