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

b001Asked:
Who is Participating?
 
warddhoogheCommented:
SELECT table.field, table.field2  FROM product INNER JOIN qprice on (product.KeyCode = qprice.KeyCode)

You might want to go through a free SQL tutorial. check out: http://www.w3schools.com/sql/default.asp
0
 
warddhoogheCommented:
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'
0
 
LowfatspreadCommented:
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?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
b001Author Commented:
I am sorry

The QPrice table only has the following columns

                                 Keycode
                                 Price
       
0
 
b001Author Commented:
The would like link the 2 databases on kaycode, there is no relatonship set at the moment.
0
 
warddhoogheCommented:
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.
0
 
b001Author Commented:
KeyCode is the common field.
0
 
sarabandeCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.