Solved

Need to put multiple tables into an OleDbDataAdapter

Posted on 2007-11-22
2
233 Views
Last Modified: 2013-12-16
I have this code working fine.  But I need to access the ZipCode, contained in the ZipCodes table, from the ordersDataSet.  Can I do that?  I had the impression that the SQL comand was creating one big long record by adding the columns from various tables, when the CustomerID and ZipCode match between the tables.  But how do I reference the ZipCode?  The exception I get says the ZipCode is not part of the OrderHeaders table.


Thanks,
newbieweb


                connectString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=" + DataSource + ";Jet OLEDB:Database";

                sql = "SELECT * FROM OrderHeaders, CustomerFiles, ZipCodes WHERE ";
                sql += "OrderHeaders.CustomerID=CustomerFiles.CustomerID AND ";
                sql += "CustomerFiles.ZipCode=ZipCodes.ZipCode";

                if (orderDataAdapter == null || orderDataSet == null)
                {
                    orderDataAdapter = new OleDbDataAdapter(sql, connectString);
                    myOrderHistory = new MyOrderHistory(Handles, this);
                    orderDataSet = new DataSet();
                    orderDataAdapter.Fill(orderDataSet, "OrderHeaders");
                }
                else
                {
                    orderDataSet.Clear();
                    orderDataAdapter.Fill(orderDataSet, "OrderHeaders");
                }
                int numRows = orderDataSet.Tables["OrderHeaders"].Rows.Count;
                int tables = orderDataSet.Tables.Count;
                myOrderHistory.CreateNewOrders(orderDataSet);
0
Comment
Question by:newbieweb
2 Comments
 
LVL 6

Accepted Solution

by:
-DJL- earned 500 total points
ID: 20336671
Try the SQL statement below.

You need to use the JOIN command if you want the output to be one big table
SELECT * FROM OrderHeaders INNER JOIN CustomerFiles ON (OrderHeaders.CustomerID=CustomerFiles.CustomerID) INNER JOIN ZipCodes ON (CustomerFiles.ZipCode=ZipCodes.ZipCode)

Open in new window

0
 

Author Comment

by:newbieweb
ID: 20336681
I tried this:

orderDataAdapter.Fill(orderDataSet, "OrderHeaders, CustomerFiles, ZipCodes");

and it worked great.

Thanks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

785 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