C#将数据库中的值逐一导入到combox的itms

    科技2022-07-13  127

    string sqlStr = "select 需要获取的列明名 from 查询的表 where 进行筛选的列 ='" + 筛选内容 + "'"; adapter = new MySqlDataAdapter(sqlStr, conn); dsCountry = new DataSet(); adapter.Fill(dsCountry, "查询的表"); if (dsCountry != null && dsCountry.Tables.Count >= 0 && dsCountry.Tables[0].Rows.Count > 0)//判断是否有内容在进行添加,减少不必要的损耗 { comboBox2.Items.Clear();//清除items for (int i = 0; i < dsCountry.Tables[0].Rows.Count; i++) { comboBox2.Items.Add(dsCountry.Tables[0].Rows[i]["需要获取的列名"].ToString()); } }

    劳烦点个赞,添加个关注

    Processed: 0.010, SQL: 8