Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7792121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:05:40+00:00 2026-06-01T22:05:40+00:00

I am using BindingSource and I want to use some SQL code to perform

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:05:42+00:00Added an answer on June 1, 2026 at 10:05 pm

    The BindingSource.Filter applies a Filter to the data that is already been loaded into your DataGridView. 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 JOIN on that data then you will need to perform another search and load the DataGridView. 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:

    1. Load you DataGridView
    2. Use selects the Filter or records they want
    3. Performs a second search with your INNER JOIN
    4. reload your DataGridView with the new data.

    EDIT here is some code that might get your started:

    How to: Bind Data to the Windows Forms DataGridView Control

    private void GetData(string selectCommand)
    {
        try
        {
            // Specify a connection string. Replace the given value with a 
            // valid connection string for a Northwind SQL Server sample
            // database accessible to your system.
            String connectionString =
                "Integrated Security=SSPI;Persist Security Info=False;" +
                "Initial Catalog=Northwind;Data Source=localhost";
    
            // Create a new data adapter based on the specified query.
            dataAdapter = new SqlDataAdapter(selectCommand, connectionString);
    
            // Create a command builder to generate SQL update, insert, and
            // delete commands based on selectCommand. These are used to
            // update the database.
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
    
            // Populate a new data table and bind it to the BindingSource.
            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            bindingSource1.DataSource = table;
    
            // Resize the DataGridView columns to fit the newly loaded content.
            dataGridView1.AutoResizeColumns( 
                DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
        }
        catch (SqlException)
        {
            MessageBox.Show("To run this example, replace the value of the " +
                "connectionString variable with a connection string that is " +
                "valid for your system.");
        }
    }
    
    private void Button1_Click(object sender, EventArgs e)
    {
        // Bind the DataGridView to the BindingSource
        // and load the data from the database.
        dataGridView1.DataSource = bindingSource1;
        GetData("select * from Customers");
    }
    

    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

    private void Button1_Click(object sender, EventArgs e)
    {
        // Bind the DataGridView to the BindingSource
        // and load the data from the database.
        dataGridView1.DataSource = bindingSource1;
    
        string sqlQuery = string.Empty;
    
        if(your check goes here)
        {
            sqlQuery = "select * from Customers";
        }
        else 
        {
            sqlQuery = "your new SQL";
        }
    
        GetData(sqlQuery);
    }
    

    then you would rebind your data based on the new query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView bound to a table using BindingSource and Linq to SQL
I am using BindingSource.Filter to get a small list of rows. Either I can
For a WinForms VB.Net application, I use the Bindingsource's filtering capacity to filter data,
Howdy, using vs2008 winforms. I want to be able to use a slightly customised
I have bind 2 separate tables using BindingSource. Left grid contains student table and
I'm fairly new to database programming in WinForms, and have been using BindingSource, DataSet,
I have a BindingSource that I'm using in winforms data binding and I'd like
Using LINQ on collections, what is the difference between the following lines of code?
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
Using Nunit, I want to be able to write a test fixture that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.