简体   繁体   English

C#,Visual Studio 2008

[英]C#, Visual Studio 2008

In TextBox collection i load the data from Database Table, Its containing data like this "01-carrot" I'm set AutoCompleMode for textbox. 在TextBox集合中,我从数据库表中加载数据,其中包含像“ 01-carrot”这样的数据,我为文本框设置了AutoCompleMode。 But if i enter '01' its showing the related collection but but if i enter 'c' in starting it's not showing any collection Please Suggest me 但是,如果我输入“ 01”则显示相关集合,但是如果我输入“ c”则未显示任何集合,请建议我

I tried Code Like This, And Loaded this enter code here in Load_page event. 我试过这样的代码,并在Load_page事件中将此enter code here加载到enter code here

AutoCompleteStringCollection MyCollection;
private void clubitem_no()
{
    try
    {
       // string a = txtitem.Text + "%";
       // DataTable allnames = new DataTable();
       // MySqlCommand cmdauto = new MySqlCommand("SELECT CONCAT(product_id,'-',product_name)AS product_name FROM product_details WHERE product_id LIKE  '"+ a + "' OR product_name LIKE '" + a + "'", conn);
        MySqlCommand cmdauto = new MySqlCommand("SELECT CONCAT(product_id,'-',product_name)AS product_name FROM product_details ", conn); 
      conn.Open();
        MySqlDataReader newdr = cmdauto.ExecuteReader();
         MyCollection = new AutoCompleteStringCollection();
        while (newdr.Read())
        {
            string b = newdr.GetString(0);
            MyCollection.Add(newdr.GetString(0));

        }
      // txtitem.AutoCompleteCustomSource = MyCollection;
       txtitem.AutoCompleteMode = AutoCompleteMode.Suggest;
       txtitem.AutoCompleteSource = AutoCompleteSource.CustomSource;
      // AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();
       txtitem.AutoCompleteCustomSource = MyCollection;
        newdr.Close();
        conn.Close();
    }
    catch (MySqlException ex)
    {
        MessageBox.Show(ex.ToString());
        conn.Close();
    }
}

You should use % after like. 喜欢后应使用%。 Example: 例:

SELECT CONCAT(product_id,'-',product_name)AS product_name FROM product_details WHERE product_id LIKE  '%"+ a + "%' OR product_name LIKE '%" + a + "%'"

Check here for more details 在这里查看更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM