c#windows中使用coboBox控件,下拉后显示mysql数据库中表的内容。可以用coboBox绑定数据库,可是显示出的有重复项(因为数据库中的表有重复项) 想用代码实现这一功能,不能有重复。 谢谢,不胜感激!

解决方案 »

  1.   

    把combox的数据源改为select distinct fldname from tblName.
        [align=center]====  ====
    [/align]
    .
    贴子分数<20:对自已的问题不予重视。
    贴子大量未结:对别人的回答不予尊重。
    .
      

  2.   

    不是已经回过一贴了么?楼主还不会使用distinct?
      

  3.   

    能说的详细点吗?
    把distinct写到具体的那一段?
    private void Form1_Load(object sender, EventArgs e){}?
    还是
    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){}?
      

  4.   

    不会。我知道要用distinct,可是代码不知道怎么写。mysql第一次用。
             private void Form1_Load(object sender, EventArgs e){    
                  string find = "select distinct casing1 from 1";
                string connStr = "server=localhost;uid=root;pwd=1;database= design";
                MySQLConnection myConnection = new MySQLConnection(connStr);
                MySQLDataAdapter myda = new MySQLDataAdapter(find, myConnection);
                DataSet ds = new DataSet();
                myda.Fill(ds, "ds");            comboBox1.DisplayMember = "casing1";
                comboBox1.DataSource = ds.Tables["ds"].DefaultView;
                }
    就是有错误。
      

  5.   

    这样试试
    string find = "select distinct casing1 from 1";
    string connStr = "server=localhost;uid=root;pwd=1;database= design";
    MySQLConnection myConnection = new MySQLConnection(connStr);
    MySQLDataAdapter myda = new MySQLDataAdapter(find, myConnection);
    DataSet ds = new DataSet();
    myConnection.Open();
    myda.Fill(ds);
    myConnection.Close();
    comboBox1.DataSource = ds.Tables[0].DefaultView; 
    comboBox1.DisplayMember = "casing1";
      

  6.   

     myConnection.Open();有错误。MySQLDriverCS Exception: MySQLDriverCS Error: can't connect.Access denied for user 'ODBC'@'localhost' (using password: NO)
      

  7.   

    很明显根本不是sql语句的问题,而是你的连接就没打开偶对MySql研究不多,只能say sorry了