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

رضا جافری 1,291 Reputation points

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:


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


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()+ "'",   
OleDCmd.CommandType = System.Data.CommandType.Text;  
OleDbDataReader DataReader = OleDCmd.ExecuteReader();  
while (DataReader.Read())  
  //Like this  
  //MemberDataGrid.Rows[0] = DataReader[All].ToString();  


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

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