0

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.

5
Contributors
6
Replies
23
Views
6 Years
Discussion Span
Last Post by Sarfraz409
0

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?

0

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;
0

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

0

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)";
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.