Page 1 of 1

SQL.Text doesn't seem to be working in Delphi 10.3

Posted: Mon 17 Feb 2020 20:13
by SteveInIT
I have an import routine that sets up data in an array and loops to HiArr

On each loop it assigns the last name and first name like so...

ILName := ArrayofUser[x].LName; //ImportLastName
IFName := ArrayofUser[x].FName; //ImportFirstName

Now I need to see if the ILName and IFName already exist in the table.

**FADC is another unit that holds the tables in the project
**I prefix all TUniQuerys with UQ, so I know what they are (just telling for readability)

FADC.UQUserTBLTest.SQL.Clear;
FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserLName = ' + ILName +
' AND UserFName = ' + IFName;
FADC.UQUserTBLTest.Open;

First record being imported from the array is ILName of 'Barr**', ILFName of 'Mary'

Debugger Exception is Project Inventory.exe raised exception classs EMSError with message 'Invalid column name 'Mary', Invalid Column name 'Barr**'.'.

Funny thing is I can do this earlier....

FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserTypeIDNo = ' + InttoStr(UserTypeIDNo) +
' AND DistrictIDNo = ' + InttoStr(DistrictIDNo);

And get no "invalid column name" errors. Same format.

Anyone have a clue what I'm doing wrong?

Thanks!

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Posted: Mon 17 Feb 2020 22:41
by SteveInIT
Forgot to mention, I'm using MS SQL Server 2012

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Posted: Tue 18 Feb 2020 21:10
by SteveInIT
Ok, I finally got it.

Instead of what is in the original post, when working with the strings for the SQL.Text statement, you need to hyphenate as follows around the variables:

FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserLName = ''' + ILName + ''' and UserFName = ''' + IFName +''''; // + '' + ILName + '' + ' AND UserFName = ' + '' + IFName + '';

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Posted: Tue 18 Feb 2020 21:14
by SteveInIT
I had some commented text in there....

Instead of what is in the original post, when working with the strings for the SQL.Text statement, you need to hyphenate as follows around the variables:

FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserLName = ''' + ILName + ''' and UserFName = ''' + IFName +'''';

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Posted: Mon 24 Feb 2020 12:56
by Stellar
Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.