在C#Windows窗体应用程序中搜索Microsoft Access记录?

时间:2011-04-11 17:21:49

标签: c# winforms ms-access

如何在C#Windows窗体应用程序中搜索Microsoft Access记录?

代码:

    private void btnsearch_Click(object sender, EventArgs e)
    {
        dataAdapter = new OleDbDataAdapter("SELECT * from  tblStudents WHERE studid='" + 
                                             txtstudid.Text + "' ",
                                           conn);
        dataset = new DataSet();

        dataAdapter.Fill(dataset);
        dataGridView1.DataSource = dataset.Tables[0];
    }

1 个答案:

答案 0 :(得分:0)

//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();

//set the BindingSource DataSource
bSource.DataSource = ds.Tables[0];

//set the DataGridView DataSource
dataGridView1.DataSource = bSource;

要将更改恢复到数据库,您只需调用Update()的{​​{1}}并使用OleDbDataAdapter作为参数来完成此操作。

DataTable