MySql & combo Databinding

I

Ivan Sammut

Here is my code.

MySqlConnection iCon = new MySqlConnection("Network
Address=localhost;Initial Catalog='invoices'; User
Name='root';Password='tottenham'");
MySqlCommand iCmd = new MySqlCommand("select Acc_Code,Acc_name from
accounts", iCon);
iCon.Open();
MySqlDataReader iRec = iCmd.ExecuteReader();
comboBox1.DataSource = iRec;
comboBox1.DisplayMember = "acc_name";
iCon.Close();

but I am getting an error on the line "Complex DataBinding accepts as a
data source either an IList or an IListSource." on the line
comboBox1.DataSource = iRec.

What am i Doing wrong

Thanks
Ivan
 
I

Ignacio Machin \( .NET/ C# MVP \)

HI,

Ivan Sammut said:
Here is my code.

MySqlConnection iCon = new MySqlConnection("Network
Address=localhost;Initial Catalog='invoices'; User
Name='root';Password='tottenham'");
MySqlCommand iCmd = new MySqlCommand("select Acc_Code,Acc_name from
accounts", iCon);
iCon.Open();
MySqlDataReader iRec = iCmd.ExecuteReader();
comboBox1.DataSource = iRec;
comboBox1.DisplayMember = "acc_name";
iCon.Close();

but I am getting an error on the line "Complex DataBinding accepts as a
data source either an IList or an IListSource." on the line
comboBox1.DataSource = iRec.

From the message it seems like if MySqlDataReader does not support IList or
IListSource , which I would find weird.

try to do this:
IList list = iRec;

and see if the compiler complains
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top