Redirect SQL-Replies to Variables

Hello,

usually i use a DBGrid to display information, returned from an ODBC/Access Connection.
But for a small project, i just have a simple table containing three fields.
I'd like to talk in SQL to that MDB and display the results in three Labels.

The fields are, EmpoyeNumber, EymployeName and eMail

The program attempts to build an easy interface (using EditBoxes) where u can search either by the Number, the Name or the eMail address.
I know how to do it the conventional way, but not using LAbels
LVL 2
omsecAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
You can do it like this:

Do your query as usual, and use a TDBNavigator or whatever to move through the records...

Then to display the contents of a record in labels do this:

Label1.caption := MyQuery.FieldByName['Field1'].AsString;
Label2.caption := MyQuery.FieldByName['Field2'].AsString;
Label3.caption := MyQuery.FieldByName['Field3'].AsString;

Cheers,
Raymond.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lsaeCommented:
In stead of using labels you can use DBText

Greetings,
Ludo
0
omsecAuthor Commented:
Can i use a TDataSource, TQuery and a TDataBase as usual ?

I just need one Record at once. The user enters either a Number, a Name or an eMAil-Address and the MBD-Server proceeds the queries based on the SQL-Statements given from my Application.

Maybe u can post some more code, also the statements to send the SQL over the "Find"-Button to the ODBC ?

thx
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

rwilson032697Commented:
>Can i use a TDataSource, TQuery and a TDataBase as usual ?

yes.

The only difference is that you are displaying the data in a different way - the way the user tells you what to get, and the way that you get it should not need to change.

You might do this in your 'find' procedure:

MyQuery.sql.clear;
MyQuery.sql := format('Select * from MyTable where email = %1', [EditEmail.text]);
MyQuery.Open;
MyQuery.First;
Label1.caption := MyQuery.FieldByName['Field1'].AsString;
Label2.caption := MyQuery.FieldByName['Field2'].AsString;
Label3.caption := MyQuery.FieldByName['Field3'].AsString;

Cheers,
Raymond.
0
omsecAuthor Commented:
before, you mentioned something, i could use to browse thru all Records.
I should also know this more detailed now, because at the Program's Start, i want to fill some Comboboxes with Fields of all Records.

eg.
Name
----
1
2
3
4

The user select then the name
0
rwilson032697Commented:
You can fill a combo box with a field from some records like this:

(Assuming we have a query with the records in it ...)

MyQuery.First;
MyCombo.items.clear;
While Not MyQuery.Eof do  
  begin
    MyCombo.items.add(Myquery.fieldbyname['MyField'].AsString);
    MyQuery.next;
  end;

Cheers,

Raymond.

0
omsecAuthor Commented:
when i get an SQL-Statement directly from the user, i cant use FieldByName, cause Delphi sais field X is not found.
Therefore, is it the only way to parse the SQL-String and find out what fields are requested, when i want to add them into to a ListView or is there another way ?
0
rwilson032697Commented:
You don't need to parse the SQL, as the Fields property of the TQuery will contain the names of the fields after the query has executed.

eg:

for i:=0 to MyQuery.fields.count - 1 do
  MyCombo.items.add(MyQuery.fields[i].name);

Cheers,

Raymond.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.