0

I have a school PAT project where I need to do something extra, and in order to do so I need to do the following (I am using delphi 7 and ms access):
I want to set sql code = to a variable in order to use the var for something like a calculation.
I am thinking something like this:

s(var):=ADOQuery1.SQL.Text:='SELECT Birthdate where username = '+edtUsername.text;

So basically I want to set a specific ms access cell = to a var in delphi.

2
  • LOL Who is this?? MSC "programers" Commented Oct 20, 2013 at 9:58
  • Cause what you want is in the back of our book (P214) Commented Oct 20, 2013 at 10:08

1 Answer 1

4

You trying to do too much in one line.

You set the SQL.Text
Then run the Query.
Then read one line into your variable.

Furthermore never inject parameters directly into a query; this leads to SQL injection vulnerabilities. Use parameters instead.

In pseudo code:

 ADOQuery1.SQL.Text:='SELECT Birthdate where username = :name';
 ADOQuery1.Parameters.ParamByName('name'):= aname;   <<-- save way to use parameters.
 ADOQuery1.RunQuery;
 var1:= ADOQuery1.FieldByName('BirthDate').AsDate;

Obviously you need to fix the SQL statement, because it is incomplete and tweak the code a little. But I'll leave that as an exercise.

Here's the documentation for TADOQuery: http://docwiki.embarcadero.com/Libraries/XE5/en/Data.Win.ADODB.TADOQuery

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.