按钮单击以搜索多个Access表

时间:2016-08-22 00:36:46

标签: c#

我有一个简单的功能,可以通过按钮点击在Access表中搜索给定的序列号。

有没有办法添加到下面的内容中搜索多个表以获取序列号并在datagridview中显示?

private void searchItembtn_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(serialSearch.Text))
        {
            try
            {
                connection.Open();

                OleDbCommand command = new OleDbCommand();
                command.Connection = connection;

                command.Parameters.Add("@searchSerial", OleDbType.VarWChar).Value = serialSearch.Text;
                string searchFB = "SELECT * FROM Inventory WHERE SerialNumber = @searchSerial";
                command.CommandText = searchFB;

                connection.Close();
                OleDbDataAdapter db = new OleDbDataAdapter(command);
                DataTable dt = new DataTable();
                db.Fill(dt);
                dataGridFB.DataSource = dt;

            }

            catch (OleDbException ex)
            {
                MessageBox.Show(ex.Message);
                connection.Close();
            }
            searchHide();
            connection.Close();
        }
    }

0 个答案:

没有答案