C# Filling Combo box with Column name of Database not Column values

前端 未结 4 1993
无人及你
无人及你 2021-01-29 11:19

I know it\'s been asked many times and there\'s so many resources about this but believe me i tried those, Unfortunately same thing is always happen. I really don\'t know why my

4条回答
  •  無奈伤痛
    2021-01-29 12:08

    actually your not using your DataReader but you just add Code, Model and ItemDescription item for each row found with the MySQL query.

    cbox_order.Items.Add("Code").ToString();
    cbox_order.Items.Add("Model").ToString();
    cbox_order.Items.Add("Itemdescription").ToString();
    

    If you want to use the result of the MySQL query you can try this instead:

    cbox_order.Items.Add(reader["Code"].ToString()).ToString(); // Change "Code" by the column name into the database
    cbox_order.Items.Add(reader["Model"].ToString()).ToString(); // Change "Model" by the column name into the database
    cbox_order.Items.Add(reader["Itemdescription"].ToString()).ToString(); // Change "Itemdescription" by the column name into the database
    

    Don't forget to close the reader at the end

    reader.Close();
    

    EDIT

    if you want the column name instead of data you can use this query, but that's useless if you already know the column name.

    SELECT COLUMN_NAME FROM information_schema.columns WHERE table_schema='databasename' AND table_name='tablename'
    

提交回复
热议问题