开发者

Searching for Microsoft Access records in a C# Windows Forms application?

开发者 https://www.devze.com 2023-02-24 09:45 出处:网络
How to search for a Microsoft Access record in a C# Windows Forms application? Code: private void btnsearch_Click(object sender, EventArgs e)

How to search for a Microsoft Access record in a C# Windows Forms application?

Code:

    private void btnsearch_Click(object sender, EventArgs e)
    {
        dataAdapter = new OleDbDataAdapter("SELECT * from  tblStudents WHERE studid='" + 
                                             txtstudid.Text + "' ",
                                           conn);
        dataset = new Dat开发者_开发问答aSet();

        dataAdapter.Fill(dataset);
        dataGridView1.DataSource = dataset.Tables[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;

To get the changes back into the database, all you have to do is call the Update() of the OleDbDataAdapter with the DataTable as the argument to accomplish this.

da.Update(ds.Tables[0]);
0

精彩评论

暂无评论...
验证码 换一张
取 消