combobox怎样绑定数据库中的某个列,谢谢

解决方案 »

  1.   

    SqlConnection myConnection = new SqlConnection();
    string strConn = "server=你的服务器名;uid=用户名;pwd=你的密码;database=数据库名";
    myConnection.ConnectionString = strConn;
    string strCmd = "select 列名 from 表名";
    SqlCommand myCommand = new SqlCommand(strCmd,myConnection);
    myCommand.Connection = myConnection;
    SqlDataReader myReader;
    myConnection.Open();
    myReader = myCommand.ExecuteReader();
    while(myReader.Read())
     {
    categoryComboBox.Items.Add(myReader.GetString(0));
     }
    myConnection.Close();注:categoryComboBox就是要绑定的控件.
      

  2.   

    this.ComboBox.DataSource = dataset_Tmp.Tables[0];
    this.ComboBox.DisplayMember = 要显示的字段;
    this.ComboBox.ValueMember   = 标识的字段;