如何从表格填充组合框 [英] how to fill combo box from table

查看:58
本文介绍了如何从表格填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个简单的问题.

我的屏幕上有三个组合框.

我的SQL 2008中有一个名为tbCountries的表.


现在我想从数据库中查询国家/地区,然后下拉组合框.

I am here with simple question.

I have a screen with three combo Box.

I have a table with name tbCountries in my sql 2008.


now i want to papulate the countries from my database.and drop down my combo box.

how can i do this?

推荐答案


尝试这样:

try like this:
public void FillComboBox()
   {
       String ConnStr = "Data Source=ServerName;Initial Catalog=DBNamae;User ID=UserName;Password='password';";
       String SQL = "SELECT * FROM Countries";
       SqlDataAdapter ad = new SqlDataAdapter(SQL, ConnStr);
       DataSet ds = new DataSet();
       ad.Fill(ds);

       comboBox1.DataSource = ds.Tables[0];
       comboBox1.DisplayMember = "CountryName";
   }


这篇关于如何从表格填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆