Skip to content
Advertisement

Why am I getting an Error with TADOQuery select statement?

Every time that I try to set the caption of this variable, it gives me “unspecified error” and I have concluded…

I’ve tried to set the caption straight from the TADOQuery and by assigning the value to a variable then loading it to the caption, but either way I get an unspecified error.

    qry1.SQL.Text := 'SELECT Number of Games Owned FROM Users WHERE UserID = "' + sLoggedInUser + '";';
    qry1.Open;
    iCountGames := qry1['Number of Games Owned'];
    lblUserGamesOwned.Caption := 'Games Owned: ' + IntToStr(iCountGames); 

Database design:

Field Name               Data Type         Description
UserID                   Short Text        Maximum characters is 6
FirstName                Short Text        Maximum characters is 25
LastName                 Short Text        Maximum characters is 25
Cell Number              Short Text        Maximum characters is 10
Number of Games Owned    Number            Integer 

I expect the code to load the value into the variable, and then the variable is used to set the caption of the TLabel, but all that happens is the unspecified error pops up, and the TLabel stays unchanged.

Advertisement

Answer

I imagine that you just need braces around the column name:

SELECT [Number of Games Owned] FROM Users WHERE UserID = "' + sLoggedInUser + '";';

I would also recommend that you use parameters to pass in UserId rather than munging the query string.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement