?
Solved

join 2 database

Posted on 2011-09-26
9
Medium Priority
?
184 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:b001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Expert Comment

by:warddhooghe
ID: 36600986
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
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36601117
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
 

Author Comment

by:b001
ID: 36601264
I am sorry

The QPrice table only has the following columns

                                 Keycode
                                 Price
       
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:b001
ID: 36601279
The would like link the 2 databases on kaycode, there is no relatonship set at the moment.
0
 
LVL 5

Expert Comment

by:warddhooghe
ID: 36601396
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
 

Author Comment

by:b001
ID: 36707939
KeyCode is the common field.
0
 
LVL 5

Accepted Solution

by:
warddhooghe earned 2000 total points
ID: 36708705
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
 
LVL 35

Expert Comment

by:sarabande
ID: 36709798
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question