I want use Inner Join link 2 table and display in a datagridview.
For example,
PDC_FG Table contain PONO,Customer
Customer Table contain Customer, Zone

2 table has same field is Customer.

ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
            string name = conSettings.ProviderName;
            string providerName = conSettings.ProviderName;
            string ConnectionString = conSettings.ConnectionString;



            string sql = "SELECT PDC.PONO,PDC.Customer,Customer.Zone From PDC INNER JOIN Customer WHERE PDC.Customer=Customer.Customer";
            OleDbConnection connection = new OleDbConnection(ConnectionString);
            connection.Open();
            sCommand = new OleDbCommand(sql, connection);
            sAdapter = new OleDbDataAdapter(sCommand);
            sBuilder = new OleDbCommandBuilder(sAdapter);
            sDs = new DataSet();
            sAdapter.Fill(sDs, "PDC_FG");
            sTable = sDs.Tables["PDC_FG"];
            connection.Close();
            dataGridView1.DataSource = sDs.Tables["PDC_FG"];
            dataGridView1.ReadOnly = true;

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

These code cannot run.Hope any expert can help me.

At line #08 you have given the table name PDC where at line # 15, 16 and 18 you are giving table names PDC_FG why?

At line #08 you have given the table name PDC where at line # 15, 16 and 18 you are giving table names PDC_FG why?

Original is PDC_FG, I change to PDC become more short a little.I'm not change in my system. I want to know how to display 2 table in datagridview in C# only.

ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
            string name = conSettings.ProviderName;
            string providerName = conSettings.ProviderName;
            string ConnectionString = conSettings.ConnectionString;



            string sql = "SELECT PDC.PONO,PDC.Customer,Customer.Zone From PDC INNER JOIN Customer WHERE PDC.Customer=Customer.Customer";
            OleDbConnection connection = new OleDbConnection(ConnectionString);
            connection.Open();
            sCommand = new OleDbCommand(sql, connection);
            sAdapter = new OleDbDataAdapter(sCommand);
            sBuilder = new OleDbCommandBuilder(sAdapter);
            sDs = new DataSet();
            sAdapter.Fill(sDs, "PDC");
            sTable = sDs.Tables["PDC"];
            connection.Close();
            dataGridView1.DataSource = sDs.Tables["PDC"];
            dataGridView1.ReadOnly = true;

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

one way (not the best at all) is to create a table, insert the select results and pass that table as datasource to the grid since you are using datasources

and before app exit or whatever, just drop the table

I'm already solved problem myself.Just add ()

string sql = "SELECT PDC.PONO,PDC.Customer,Customer.Zone From (PDC INNER JOIN Customer ON PDC.Customer=Customer.Customer)";

very good

can you show what you have written in this line in place of table name
sAdapter.Fill(sDs, "PDC");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.