Solved

join 2 database

Posted on 2011-09-26
9
166 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
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
 

Author Comment

by:b001
ID: 36601279
The would like link the 2 databases on kaycode, there is no relatonship set at the moment.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 500 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 32

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now