I am using BindingSource and I want to use some SQL code to perform an Inner Join.
My code for this doesn’t work
ticketsBindingSource.Filter = "SELECT u.CallerName, t.* FROM users u INNER JOIN tickets t ON u.id = t.user WHERE u.CallerName = 'joe.smith' AND t.ProblemStatus = 'Open'";
But the following does work
ticketsBindingSource.Filter = "ProblemStatus = 'Open'";
How can I run my InnerJoin query and update my datagridview?
The
BindingSource.Filterapplies a Filter to the data that is already been loaded into yourDataGridView. So if you have accounts displayed, and you are looking for one specific account, then you would filter that data by account number.The
Filter, cannot run another SQL query for you.If you want to perform an
INNER JOINon that data then you will need to perform another search and load theDataGridView. It sounds like you do not want to perform a filter, but you want to display two separate sets on data in the same grid.Your basic process would be:
EDIT here is some code that might get your started:
How to: Bind Data to the Windows Forms DataGridView Control
Once the data is bound to your grid, then you would provide the user some way to Filter, but you want them to search the data again. So you will want to use in the code some way to select which SQL you will run. So you could pass the SQL into GetData() as a string that you have set based on the users selection
then you would rebind your data based on the new query.