JamesDover Posted April 7, 2008 Posted April 7, 2008 Hello, I am trying to write a code to connect to MSSQL to a database called zzz and run a query to find all records with the word lock in a row and delete the whole line i.e. Line 234 name date phone lock. Here is what i have so far. Cheers #include <_sql.au3> $server = "x.x.x.x" $dbname = "zzz" $user = "myuser" $pass = "12345" Dim $server, $dbname, $user, $pass, $data _SQLStartup() _SQLConnect(-1,$server,$dbname,$user,$pass) $query = "sp_timesheet_check 'test.user'" $result = _SQLExecute(-1,$data) _SQLClose() MsgBox(4096,"",$result)
PsaltyDS Posted April 7, 2008 Posted April 7, 2008 (edited) Hello, I am trying to write a code to connect to MSSQL to a database called zzz and run a query to find all records with the word lock in a row and delete the whole line i.e. Line 234 name date phone lock. Here is what i have so far. Cheers By having Dim after the values are set, you are wiping out your variable contents. Try this way:#include <_sql.au3> Global $server = "x.x.x.x", $dbname = "zzz", $user= "myuser", $pass= "12345", $data _SQLStartup() _SQLConnect(-1,$server,$dbname,$user,$pass) $query = "sp_timesheet_check 'test.user'" $result = _SQLExecute(-1,$data) _SQLClose() MsgBox(4096,"",$result) Edited April 7, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
JamesDover Posted April 7, 2008 Author Posted April 7, 2008 Nice so Global is better to use then Dim? Try this way:#include <_sql.au3> Global $server = "x.x.x.x", $dbname = "zzz", $user= "myuser", $pass= "12345", $data _SQLStartup() _SQLConnect(-1,$server,$dbname,$user,$pass) $query = "sp_timesheet_check 'test.user'" $result = _SQLExecute(-1,$data) _SQLClose() MsgBox(4096,"",$result)
PsaltyDS Posted April 7, 2008 Posted April 7, 2008 Nice so Global is better to use then Dim? Try this way:#include <_sql.au3> Global $server = "x.x.x.x", $dbname = "zzz", $user= "myuser", $pass= "12345", $data _SQLStartup() _SQLConnect(-1,$server,$dbname,$user,$pass) $query = "sp_timesheet_check 'test.user'" $result = _SQLExecute(-1,$data) _SQLClose() MsgBox(4096,"",$result) Dim would have worked as well as Global. The real point was not to declare the variables AGAIN after the values were set. I try not to use Dim, because it forces me to explicitly think about Global/Local scope, which helps me avoid certain stupid errors (or at least avoid repeating them). If you run an AutoIt script with the full debugging turned on, it warns you that Dim is deprecated, meaning explicit Global/Local is preferred, and Dim might go away in some future version. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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