我有一张表table1有两个字段strUserNO,strUserName(都是字符型的),现需要把此表绑定到combobox上(windows窗体),需要在combobox下拉菜单中显示strUserName,选择后点令一提交按钮后要把所选内容对应的strUserNO写到令一表中,绑定combobox用DataReader好还是用DataSet好啊?请问combobox捆绑代码怎么写啊?谢谢各位大哥哥大姐姐!

解决方案 »

  1.   

    private void BindComboBox()
    {
      comboBox1.DataSource = dataSet1.Tables["table1"];
      comboBox1.DisplayMember = "strUserName";
    }
      

  2.   

    DataSet方便点
    是form application还是web application?
      

  3.   

    谢谢
    请问redwolf_123(雨恨云愁) 
    选择后点令一提交按钮后要把所选内容对应的strUserNO写到令一表中
    需要加一句什么代码啊?
      

  4.   

    insert into table2 (strUserNO)  
    select strUserNO from table1 where strUserName = comboBox1.Text
      

  5.   

    insert into table2 (strUserNO) values ( 
    select strUserNO from table1 where strUserName = comboBox1.Text)注意如果在程序中应该用应该写成:
    string sql="insert into table2 (strUserNO) values ( 
    select strUserNO from table1 where strUserName ='"+comboBox1.Text+"')";
      

  6.   

    我是要绑定Combobox的代码啊!!!!!!!!!
      

  7.   

    我是要绑定Combobox的代码啊!!!!!!!!!上面不是有代码了吗???建议你不要急写这些了。学学面向对象的东西吧。
      

  8.   

    意如果在程序中应该用应该写成:
    string sql="insert into table2 (strUserNO) values ( 
    select strUserNO from table1 where strUserName ='"+comboBox1.Text+"')";如果table1的strUserName列有多个相同的值怎么办???
      

  9.   

    Combobox1.DataSource = 你的数据源;
    Combobox1.DisplayMember= 列名
    Combobox1.ValueMember = 列名
      

  10.   

    anheizhizi的方法最实用也最简单!