Page 1 of 1

MyQuery and TDBLookupComboBox

Posted: Fri 11 Nov 2011 10:58
by imobile
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.

Posted: Fri 11 Nov 2011 12:14
by imobile
Sorry, field ID not found(NOT FIELD NAME).

Posted: Fri 11 Nov 2011 13:14
by AndreyZ
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";

Posted: Fri 11 Nov 2011 13:45
by imobile
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?

Posted: Fri 11 Nov 2011 14:30
by AndreyZ
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.

Posted: Fri 11 Nov 2011 15:14
by imobile
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.

Posted: Fri 11 Nov 2011 15:42
by imobile
Thanks for help.
Code is work. i used query for table2 and don't see this.

Posted: Fri 11 Nov 2011 15:52
by AndreyZ
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.

Posted: Fri 11 Nov 2011 16:00
by AndreyZ
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.

Posted: Fri 11 Nov 2011 23:04
by imobile
They direct here. :?
Thanks for good component.
Good luck.

Posted: Mon 14 Nov 2011 09:28
by AndreyZ
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.