Fill Combobox from database

后端 未结 7 1225
北海茫月
北海茫月 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 12:55

    private void StudentForm_Load(object sender, EventArgs e)
    
    {
             string q = @"SELECT [BatchID] FROM [Batch]"; //BatchID column name of Batch table
             SqlDataReader reader = DB.Query(q);
    
             while (reader.Read())
             {
                 cbsb.Items.Add(reader["BatchID"].ToString()); //cbsb is the combobox name
             }
      }
    

提交回复
热议问题