Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First and foremost, I apologize for my grammatical errors; my first language is Persian (Iran).
I want to display rows whose value is set by the user
Look at this image:

https://docs.microsoft.com/en-us/answers/storage/attachments/121295-database.png

Suppose I want to display rows that have the same values in the LastName, NumberOfBooksBorrowed, and LoanDate rows (by user input as shown below).

https://docs.microsoft.com/en-us/answers/storage/attachments/121318-filter.png

Note: I can get information from Access (2007) via the following code but i can not display it in DataGrid.

What I have tried:

OleDbCommand OleDCmd = new OleDbCommand("Select * From MemberTable Where LastName='" +
LastName_TextBox.Text.Trim() + "'And NumberOfBooksBorrowed='" +
NumberOfBooksBorrowed_TextBox.Text.Trim() + "'And LoanDate='"+LoanDate_TextBox.Text.Trim()+ "'",
OleDbConnect);
OleDCmd.CommandType = System.Data.CommandType.Text;
OleDbConnect.Open();
OleDbDataReader DataReader = OleDCmd.ExecuteReader();
while (DataReader.Read())
{
  //Like this
  //MemberDataGrid.Rows[0] = DataReader[All].ToString();
}


Thanks
Posted
Updated 5-Apr-22 7:34am
v3

1 solution

Rather than requerying the DB, use a DataView as the DataSource for the DataGridView instead of the DataTable or other collection, and set the DataSource of that to all the rows.

You can then use the DataView.RowFilter[^] to filter to the user input. And it's quick, too!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900