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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rwilson032697Connect With a Mentor Commented:
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
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
All Courses

From novice to tech pro — start learning today.