Filter DataGridView based on multiple inputs without using Linq 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 be displayed similar cell values in DataGridView. So that these values are entered by the user.
Look at this photo:


There are 3 rows in the table and there are similar values in the first and third rows (last name = Smith and loan date = 20210608). I want to display them based on user input.


I got the information from the database with the following codes, but I can not display those rows in DataGridView.

        OleDbCommand OleDCmd = new OleDbCommand("Select * From MemberTable Where LastName='" +   
        LastName_TextBox.Text.Trim() + "'And LoanDate='" + LoanDate_TextBox.Text.Trim() + "'", OleDbConnect);  
        OleDCmd.CommandType = System.Data.CommandType.Text;  
        OleDbDataReader DataReader = OleDCmd.ExecuteReader();  
        int i = 0;  
        while (DataReader.Read())  
           //like this  


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

1 answer

Sort by: Most helpful
  1. Sam of Simple Samples 5,516 Reputation points

    For WPF use DataGrid instead of DataGridView. The following will fill a DataGrid from a SQL Server database.

    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;  

    You can use OleDbConnection instead of SqlConnection and OleDbDataAdapter instead of SqlDataAdapter.

    Filtering the data is much more complicated.

    0 comments No comments