............................
............................
DataSet ds = this.GetDepartmentName();
this.comboBox1.DataSource = ds.Tables[0];后面应该怎么写啊?(我想把从数据库读出来的是数据绑定到comboBox1控件里面)
求完整代码!!!在线等

解决方案 »

  1.   

    this.comboBox1.DisplayMember = "字段名";
      

  2.   

    int count = ds.Tabel[0].Rows.Count;
    for(int i = 0;i<=count;i++)
    {
       this.ComboBox.Items.Add(ds.Tabel[0].Row[i][0].ToString())
    }
    给分吧。。
      

  3.   

    哦,好的,还有在combobox中一开始数据读进来是
    001
    002
    003
    .
    .
    .
    .
    要是我加"请选择"这么一个语句加在001前面,代码怎么写啊?
      

  4.   

    还以为你不结账了呢。
    Combox 不是有个属性吗?Items属性,直接加一个试试。
      

  5.   

    不行啊,this.ComboBox.Items.Add("请选择")是这样吗?不行啊
      

  6.   

    那就是它的Text属性了。
    this.combox.text = "请选择"
      

  7.   

    this.combo.selectedtext = "请选择"
      

  8.   

    this.comboBox1.Text = "请选择";
      

  9.   

    我这里怎么就行呢?
    要不你直接在属性面板里去加就是了。
    Text属性   填入 -- 请选择
      

  10.   


    string str ="server = (local);database = pubs;uid = sa;pwd = sa";
    SqlConnection con = new SqlConnection();
    con.ConnectionString = str;
    con.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandText = "select pub_id from titles";
    SqlDataAdapter sda = new SqlDataAdapter();
    sda.SelectCommand = cmd;
    DataSet ds = new DataSet();
    sda.Fill(ds);
    int count = ds.Tables[0].Rows.Count;
    for(int i = 0;i<count;i++)
    {
    this.comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
    }这是全部代码
    把查询语句改成你自己的表和数据库
    要还是不行我也无能为力了.
    Text属性在属性面板里去改一下就行了.