I have a simple code that can search fields in an access database. Now I need to change it to this parameters:
Search a query in all fields in one textbox something like:
"select * from Sheet where * like@*"Show the results in labels instead GridView.
I make an oleDbCommand and connect it to an oleDbConnection and my oleDbConnection is:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Database.accdb
I use of Visual C# 2010 and an .accdb Access database. This is my code:
private void btnSearch_Click(object sender, EventArgs e)
{
DataSet DSOne = new DataSet();
OleDbDataAdapter adpSearch = new OleDbDataAdapter();
adpSearch.SelectCommand = new OleDbCommand();
adpSearch.SelectCommand.Connection = oleDbConnection1;
adpSearch.SelectCommand.CommandText = " select * from Sheet where OfficeNumber like@OfficeNumber ";
adpSearch.SelectCommand.Parameters.AddWithValue("@OfficeNumber", textBox1.Text + "%");
adpSearch.Fill(DSOne, "toop");
dataGridView.DataSource = DSOne;
dataGridView.DataMember = "toop";
}
Best Regards