DataGrid row filter based on user inputs without use Linq commands in WPF (by C#)

رضا جافری 1,291 Reputation points
2021-08-07T16:57:58.27+00:00

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:

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

121318-filter.png

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

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

XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
772 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sam of Simple Samples 5,516 Reputation points
    2021-08-07T17:31:56.74+00:00

    What happened to your question I answered yesterday? This question is exactly the same as that one. I said for WPF use DataGrid instead of DataGridView. I provided the following code as sample code for doing that.

    SqlConnection SqlConnect = new SqlConnection(connectionstring);
    SqlConnect.Open();
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM dbo.Courses", SqlConnect);
    DataSet myDataSet = new DataSet();
    adapter.Fill(myDataSet, "Courses");
    Grid.DataContext = myDataSet;
    Grid.ItemsSource = myDataSet.Tables[0].DefaultView;
    

    That is for SQL Server but I explained how to use it for OLE/DB.

    Filtering is much more complicated.