MyQuery and TDBLookupComboBox

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
imobile
Posts: 12
Joined: Mon 17 Oct 2011 16:26

MyQuery and TDBLookupComboBox

Post by imobile » Fri 11 Nov 2011 10:58

Hello.
buider xe
mydac 7.01 prof no source.
mysql 5.5

Create form. Place on form MyQuery, MyDataSource,DBLookupComboBox and MyTable.MyDatasource set MyTable(id, name, data...);DBLookupComboBox set MyDataSource

Code: Select all

DBLookupComboBox1->ListField="NAME";
DBLookupComboBox1->KeyField="ID";
work fine. if in MyDataSource set MyQuery and MyQuery set "SELECT * FROM tab1", have erorr, field "NAME" no found.
What do I do not correctly? But only the chosen data from Query in DBLookupComboBox1 is necessary to me.

imobile
Posts: 12
Joined: Mon 17 Oct 2011 16:26

Post by imobile » Fri 11 Nov 2011 12:14

Sorry, field ID not found(NOT FIELD NAME).

AndreyZ

Post by AndreyZ » Fri 11 Nov 2011 13:14

Hello,

It seems that you didn't include the ID field to your SQL statement. Please make sure you included all fields that are used by the TDBLookupComboBox component. Here is an example that demonstrates the correct way to set up the TDBLookupComboBox component:

Code: Select all

MyQuery1->SQL->Text = "SELECT * FROM TEST1"; // CREATE TABLE test.test1( id INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(40) DEFAULT NULL, PRIMARY KEY (id))
MyQuery1->Open();
MyQuery2->SQL->Text = "SELECT * FROM TEST2"; // CREATE TABLE test.test2( id INT(11) NOT NULL AUTO_INCREMENT, txt VARCHAR(40) DEFAULT NULL, PRIMARY KEY (id))
MyQuery2->Open();
MyDataSource1->DataSet = MyQuery1;
MyDataSource2->DataSet = MyQuery2;
DBLookupComboBox1->DataSource = MyDataSource2;
DBLookupComboBox1->DataField = "ID";
DBLookupComboBox1->ListSource = MyDataSource1;
DBLookupComboBox1->ListField = "NAME";
DBLookupComboBox1->KeyField = "ID";

imobile
Posts: 12
Joined: Mon 17 Oct 2011 16:26

Post by imobile » Fri 11 Nov 2011 13:45

Has not understood, why two query?

Code: Select all

MyQuery1->SQL->Text = "SELECT * FROM TEST1"; // CREATE TABLE test.test1( id INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(40) DEFAULT NULL, PRIMARY KEY (id)) 
MyQuery1->Open(); 
MyDataSource1->DataSet = MyQuery1; 
DBLookupComboBox1->ListSource = MyDataSource1; 
DBLookupComboBox1->ListField = "NAME"; 
DBLookupComboBox1->KeyField = "ID";
I'am using 1 query. if 1 table like ID, NAME, DATE, SNAME
If write SELECT * FROM table1 WHERE SNAME='BLABLABLA' AND DATE>20001212
How do it with 2 query?

AndreyZ

Post by AndreyZ » Fri 11 Nov 2011 14:30

Yes, you can use the code you wrote. But this code is executed without any problems. Please change my code to make it raise the 'Field ID not found' error.

imobile
Posts: 12
Joined: Mon 17 Oct 2011 16:26

Post by imobile » Fri 11 Nov 2011 15:14

AndreyZ wrote:Yes, you can use the code you wrote.
I can't use this code but erorr, field ID not found.Unfortunately, your other message could not translate into Russian.
Earlier I used combobox and filled from query manually. But in combobox there is no second field id that is inconvenient. I used lookupcombobox together with MyTable and i liked.2 which you have specified fields I left empty, but with table it worked, and with query an error.
At me one table and of it I want to choose only a part of the data. And lookupcombobox to display one field- NAME and invisible id.

imobile
Posts: 12
Joined: Mon 17 Oct 2011 16:26

Post by imobile » Fri 11 Nov 2011 15:42

Thanks for help.
Code is work. i used query for table2 and don't see this.

AndreyZ

Post by AndreyZ » Fri 11 Nov 2011 15:52

I cannot reproduce the problem. If it is easier for you to write in Russian, you can ask this question at our Russian forum at http://www.devart.com/ru/forums/viewforum.php?f=29 . Please create a new topic at our Russian forum with detailed description of the problem. I will answer you there.

AndreyZ

Post by AndreyZ » Fri 11 Nov 2011 16:00

I didn't see your last post. It's good to see that the problem was solved. If you have any other questions about MyDAC, you can ask them at our Russian forum.

imobile
Posts: 12
Joined: Mon 17 Oct 2011 16:26

Post by imobile » Fri 11 Nov 2011 23:04

They direct here. :?
Thanks for good component.
Good luck.

AndreyZ

Post by AndreyZ » Mon 14 Nov 2011 09:28

If you have a question about any DAC products or dbExpress drivers and you want to communicate in Russian, you can ask it at our Russian forum. We don't provide Russian support for all other Devart products.

Post Reply