How to filter data using Entity Framework in a way that DataGridView be editable and context track changes?

前端 未结 2 1379
醉话见心
醉话见心 2020-12-01 13:37

I\'m using C# Windows Form Application to populate data from sql server database table using Entity Framework (EFWinForms) using the following code :

MyEnti         


        
2条回答
  •  感情败类
    2020-12-01 13:39

    While I'm not certain of your possible usage, I generally use the filter property on a binding source to select certain records without giving up the ability to update the database. Something like this:

            // Grab search string from SearchBox
            string strSearch = Convert.ToString(RichSearchBox.Text);
    
            // Apply Filter to BindingSource
            tblContactsBindingSource.Filter = "FileAs LIKE '*" + strSearch + "*'";
    

    Then use the Binding Source as the data source for the data grid view:

            // Bind DataGridView to BindingSource
            recipientGridView.DataSource = tblContactsBindingSource;
    

提交回复
热议问题