Link to home
Start Free TrialLog in
Avatar of b001
b001Flag for Afghanistan

asked on

join 2 database

Hi expert
I have 2 tables named  Product and qprice
Product has Columns
                                  keycode
                                  Group
 and QPrice column     Keycode
                                 Price
                                 Group

for selected Group
I use the following code to fill the data into tables but do not know how to join 2 in query
  Private DA As New SqlDataAdapter(" select * FROM Product'", CS)
  Private DA1 As New SqlDataAdapter(" select * FROM QPrice", CS)
    Private DS As New DataSet
    Private DS1 As New DataSet
    Private dt As New DataTable
    Private dt1 As New DataTable
      CS.Open()
        DA.Fill(DS, "Product")
        DA1.Fill(DS1, "QPrice")
        dt = DS.Tables("Product")
        dt1 = DS1.Tables("QPrice")
        DataGridView1.DataSource = dt
      DataGridView2.DataSource = dt1
I can see the results in 2 separate Grids
But I would like to see in my DataGridView3
             Keycode , Price , Group    where Keycode& group are from Product and Price from QPrice
my sql tables are very large. It takes a long time to fill Datasets. Is there another quick way to get the data and join and display in DataGridView

Please help

Avatar of warddhooghe
warddhooghe
Flag of Belgium image

i'm not a developer but would be most performant if you ask that question to your database.

SELECT keycode, price  FROM product INNER JOIN qprice on (product.group = qprice.group)

and if you want to filter some thing specific, you can add
WHERE fields = 'something'
Avatar of Lowfatspread
please confirm which column(s) link the two tables together ,,,

keycode or group...

you seem to imply you filter by the group is that so? if so how?
Avatar of b001

ASKER

I am sorry

The QPrice table only has the following columns

                                 Keycode
                                 Price
       
Avatar of b001

ASKER

The would like link the 2 databases on kaycode, there is no relatonship set at the moment.
you will need a common field to join them together. perhaps a 3rd table linking the first 2 tables together?
or perhaps an example data records from both tables will give us a better insight into what you are trying to accomplish here.
Avatar of b001

ASKER

KeyCode is the common field.
ASKER CERTIFIED SOLUTION
Avatar of warddhooghe
warddhooghe
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in c++ it is like

 voidForm1_Load(Object^ /*sender*/, System::EventArgs^ /*e*/)
{
   // Bind the DataGridView to the BindingSource
   // and load the data from the database.
   dataGridView1->DataSource = bindingSource1;
   GetData("select a.keycode, a.group, b.price from product a, qprice b where a.group = 'xxxx' and a.keycode = b.keycode");
}

Open in new window


in vb it should be like

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)  _
       Handles Me.Load

       ' Bind the DataGridView to the BindingSource
       ' and load the data from the database.

       Me.dataGridView1.DataSource = Me.bindingSource1

       GetData("select a.keycode, a.group, b.price from product a, qprice b where a.group = 'xxxx' and a.keycode = b.keycode")

   End Sub

Open in new window


the GetData in both cases would connect to database and execute the sql command.

Sara