文本框显示来自访问

时间:2017-05-06 11:37:41

标签: c#

您好我是C#的新手,我有一个带有文本框Barcode_txtBx和按钮Search_btn的窗体,它将数据表dt中的记录过滤到一条记录中文本框Manufacturer_txtBx显示数据表列制造商。我可以进行过滤,但我找不到在文本框Manufacturer_txtBx中显示相关列的方法。这是我到目前为止的代码。

private void Search_btn_Click(object sender, EventArgs e)
{
        connection.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        command.CommandText = "Select * from BookInTable where Barcode = '" + Barcode_txtBx.Text + "'";
        OleDbDataReader reader = command.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(reader);          
        Manufacturer_txtBx.Text = "";
        connection.Close();
} 

目前,Manufacturer_txtBx正在显示一个空字符串,因此我没有收到错误

1 个答案:

答案 0 :(得分:0)

这可以将数据添加到TextBoxes

     private void Search_btn_Click(object sender, EventArgs e)
    {
        connection.Open();

        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        command.CommandText = "Select * from BookInTable where Barcode = '" + Barcode_txtBx.Text + "'";
        OleDbDataReader reader = command.ExecuteReader();

        DataTable dt = new DataTable();

        dt.Load(reader);
        string data = dt.ToString();

        Manufacturer_txtBx.Text = dt.Rows[0].ItemArray[5].ToString();
        Type_txtBx.Text = dt.Rows[0].ItemArray[6].ToString();
        Model_txtBx.Text = dt.Rows[0].ItemArray[7].ToString();
        PartNumber_txtBx.Text = dt.Rows[0].ItemArray[8].ToString();
        AdditionalDetails_txtBx.Text = dt.Rows[0].ItemArray[13].ToString();
        connection.Close();

    }

Crowcoder和Steve是对的,这不会以任何方式消毒,任何有效的数据库应该是。