Fill Combobox from database

后端 未结 7 1217
北海茫月
北海茫月 2020-11-28 12:22

I have an error with a combobox

My code:

SqlConnection conn = new SqlConnection();
try
{
    conn = new SqlConnection(@\"Data Source=SHARKAWY;Initia         


        
7条回答
  •  北海茫月
    2020-11-28 13:06

    string query = "SELECT column_name FROM table_name";      //query the database
    SqlCommand queryStatus = new SqlCommand(query, myConnection);
    sqlDataReader reader = query.ExecuteReader();                               
    
    while (reader.Read())   //loop reader and fill the combobox
    {
    ComboBox1.Items.Add(reader["column_name"].ToString());
    }
    

提交回复
热议问题