0
votes

I have a simple code that can search fields in an access database. Now I need to change it to this parameters:

  1. Search a query in all fields in one textbox something like:

    "select * from Sheet where * like@*"

  2. 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

1
What is the question? - Steve
Search a query in all fields in one textbox something like: "select * from Sheet where * like@*" Show the results in labels instead GridView. - user3346389
Excuse me but this is two separate question in a topic because I worry about Junk! - user3346389

1 Answers

0
votes
adpSearch.SelectCommand.CommandText = " select * from Sheet where OfficeNumber  like %@OfficeNumber%";
adpSearch.SelectCommand.Parameters.AddWithValue("@OfficeNumber", textBox1.Text);