In in order not to cockup the actual application I now test my bits of SQL and reports as very basic programs connected to the correct tables - the frills can come later!
So this program comprises a form with grid, datasource, SQL, editbox and a button and the following code -
Query1.Close; Query1.SQL.Clear; Query1.SQL.Add ('SELECT *'); Query1.SQL.Add ('FROM Client.db'); Query1.SQL.Add('FROM ":Contract:Client.db"'); // the Alias Query1.Params[0].AsString := edit1.Text; // not working // Query1.SQL.Add('WHERE Months = ''' + edit1.Text + ''''); //this works Query1.Open;
The line I have commented as working does. But the line above brings up the error message as posted if the Value section of the Params section is left blank. But, if say, the params value "April" is entered then it works directly from the button without the editbox.
Larry I think you have won the prize in getting this to work
And thanks to Rick as well I shall give your two tips a try.
Ah yes, the alias coding ':' does show my Paradox roots, but I found the ':' used in some Delphi example or other and in the absence of any further information thought it worth a try! Out of interest if I did want to use an alias what is the correct syntax to use with Delphi? Thanks again. rt
Query1.SQL.Add('FROM ":Contract:Client.db"'); // the Alias
Aha! That looks like a query created in Paradox for Windows, and pasted in. I'm not sure the alias is being passed properly this way, and, in any case, it might be best to get into the habit of writing SQL that will still work if and when you need to move to a different database engine.
Rather than giving the alias this way, I'd suggest that you either assign the path to Query1.DatabaseName, or (my preference) get the path as a string and pass the full path in your SQL (and use single backslashes, rather than the double backslashes you've grown used to using in Paradox).
As another debugging trick, temporarily add a memo to your form, and add the line:
Memo1.Lines := Query1.SQL;
This will allow you to see just what SQL statement is being passed, which may be different from what you think.
Rick Carter Chair, Delphi/Paradox SIG Cincinnati PC Users Group
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
I should clarify that I don't know for a fact that it's a problem to use ":Contract:Client.db" in your code. SQL is passed back to the database engine for processing, so it may be that the BDE can understand something like that just fine. I just know I've never tried it that way in Delphi, and as a general principle I try to find ways to code things that are not specific to the database engine.
Like you, I've invested a lot of time and effort in learning to work with the BDE, and I've got a lot of BDE-specific code I'm still maintaining. But it may be time to realize that the BDE is an endangered species these days.
Rick Carter Chair, Delphi/Paradox SIG Cincinnati PC Users Group
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
Query1.Close; Query1.SQL.Clear; Query1.SQL.Add ('SELECT *'); Query1.SQL.Add ('FROM Client.db'); Query1.SQL.Add('FROM ":Contract:Client.db"'); // the Alias Query1.Params[0].AsString := edit1.Text; // not working // Query1.SQL.Add('WHERE Months = ''' + edit1.Text + ''''); //this works Query1.Open;
The code that you posted must be a little bit garbled, but I think I see what you are trying to do. I think you are misusing the quotes. Your code should look like:
I always feel more comfortable using the ParamByName property rather than Params[x]. Also, please remember that the ':' is the signal to Delphi that the token is a parameter.
Ah yes, the alias coding ':' does show my Paradox roots, but I found the ':' used in some Delphi example or other and in the absence of any further information thought it worth a try! Out of interest if I did want to use an alias what is the correct syntax to use with Delphi?
If you are using BDE components (which I think you are) then all of those components require you to specify a database name in a form depending on the type of database that you are using. One option is the provide a BDE alias as the database name. This is where you use your alias.
Read up on TDatabase, TTable.DatabaseName, TQuery.Databasename, etc. in the Delphi Help.