Searching for Microsoft Access records in a C# Windows Forms application?
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]);
精彩评论