【问题标题】:Reading Data From Access Database in DataGridView在 DataGridView 中从 Access 数据库中读取数据
【发布时间】:2018-12-16 07:57:24
【问题描述】:

我目前正在开发发票软件。我从 Access 数据库中读取数据的结构。我的问题是当我输入产品名称的第一个单词时,程序会在数据库中搜索,然后像传统的计费软件那样向我显示相关的产品名称。我该怎么做?

【问题讨论】:

  • 到目前为止你尝试了什么?

标签: c# winforms ms-access ms-access-2013


【解决方案1】:

如果您正在创建 Web 应用程序,则需要使用 AutoComplete Extender,如果是 Windows 桌面应用程序,则需要使用 TextBox 的 AutoCompleteMode 属性。

【讨论】:

    【解决方案2】:

    使用文本框:

    private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string strProvider = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = F:\product.accdb";
            string strSql = "Select * from product where productname like '" + textBox1.Text + "*';" ;
            OleDbConnection con = new OleDbConnection(strProvider);
            OleDbCommand cmd = new OleDbCommand(strSql, con);
            con.Open();
            cmd.CommandType = CommandType.Text;
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataTable products = new DataTable();
            da.Fill(products);
            dataGridView1.DataSource = products;
            con.Close();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-29
      • 2010-11-30
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多