【问题标题】:What is the code for Autocomplete in a ComboBox Using C# and Access 2017?使用 C# 和 Access 2017 在组合框中自动完成的代码是什么?
【发布时间】:2017-11-15 07:54:38
【问题描述】:

我想使用 C# 和 Access 2017 在 ComboBox 中进行自动完成。所以我使用了这段代码......但我不明白“&lt”和“&gt”的含义。这些地方有一些错误。请帮我解决这个错误。

private void Autocomplete()
    {
        string query; 
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/Neth1.accdb");
        //opening connection
        con.Open();
        try
       {
        //initialize a new instance of sqlcommand
         OleDbCommand cmd = new OleDbCommand();
        //set a connection used by this instance of sqlcommand
         cmd.Connection = con;
         //set the sql statement to execute at the data source
         cmd.CommandText = query;

          OleDbDataAdapter da = new OleDbDataAdapter();
         //set the sql statement or stored procedure to execute at the data source
         da.SelectCommand = cmd;
         //initialize a new instance of DataTable
         DataTable dt=new DataTable ();
         //add or resfresh rows in the certain range in the datatable to match those in the data source.
         da.Fill(dt);


         foreach (DataRow r in dt.Rows)
         {
         //getting all rows in the specific field|Column
         var rw = r.Field < string >("IMEI");

         //Set the properties of a combobox to make it auto suggest.
         comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
         comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
         //adding all rows into the combobox
         comboBox1.AutoCompleteCustomSource.Add(rw);

         }
        }
         catch (Exception ex)
         {
          //catching error 
          MessageBox.Show(ex.Message);
         }
         //release all resources used by the component
         da.Dispose(); 
         //clossing connection
         con.Close();
    }

【问题讨论】:

    标签: c# ms-access combobox autocomplete


    【解决方案1】:

    < = 小于

    > = 大于

    var rw = r.Field < string >("IMEI");
    

    变成

    var rw = r.Field<string>("IMEI");
    

    【讨论】:

      猜你喜欢
      • 2018-05-01
      • 2011-09-08
      • 2011-07-31
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      相关资源
      最近更新 更多