Click here to Skip to main content
16,014,650 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
MySqlConnection con = new MySqlConnection("Server=localhost;UID=root;Database=db_cignal");
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select Date from inventoryout";
MySqlDataReader reader;

reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
DataTable dtt = new DataTable();
dt.Columns.Add("Date", typeof(String));
dtt.Columns.Add("Date", typeof(String));
dt.Load(reader);

cbTo.DisplayMember = "Date";
cbTo.ValueMember = "Date";
cbFrom.DisplayMember = "Date";
cbFrom.ValueMember = "Date";
cbFrom.DataSource = dtt;
cbTo.DataSource = dt;

con.Close();
Posted
Updated 22-Feb-15 4:37am
v2
Comments
_bluRe_ 22-Feb-15 10:36am    
i have two combo box (first, second). the problem is when i select in the first, the selectedvalue in the first is the same as the second. so generally everytime i choose, its generates to the other

1 solution

MySqlConnection con = new MySqlConnection("connection...");
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select Date from inventoryout";
MySqlDataReader reader;

reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("Date", typeof(String));
dt.Load(reader);

cbFrom.ValueMember = "Date";
cbFrom.DisplayMember = "Date";
cbFrom.DataSource = dt;

cbTo.BindingContext = new BindingContext();
cbTo.ValueMember = "Date";
cbTo.DisplayMember = "Date";
cbTo.DataSource = dt;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900