Solved

join 2 database

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

 
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 33

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 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

12 Experts available now in Live!

Get 1:1 Help Now