MySql & Databinding

  • Thread starter Thread starter Ivan Sammut
  • Start date Start date
I

Ivan Sammut

Hi ppl,

Everyone has a clue how I can do a databinding on a combobox when my
data is coming from a MySql database cause the MySqlCommand does not have
the ".fill()" procedure.

Thanks
Ivan
 
Everyone has a clue how I can do a databinding on a combobox when my data
is coming from a MySql database cause the MySqlCommand does not have the
".fill()" procedure.

Use a MySqlDataReader
 
Populate oleDBDataReader using OleDBCommand
Set the DataSource of DropDownlist to datareader
Call DataBind Function of DropDownlist
Set the DataTextField of DropDownlist to the name of field you want to show
Set the DataValueField of DropDownlist to the name of field you want as
backend value
 
Could u pls elaborate a bit. What do I do after I run the SqlDataReader?

1) Set the DataSource of your combobox to the MySqlDataReader object.
2) Set the DataTextField and DataValueField of your combobox to the field
names in your MySqlDataReader object
3) Call the DataBind method of your combobox
 
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
 
Back
Top