Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to put multiple tables into an OleDbDataAdapter

Posted on 2007-11-22
2
Medium Priority
?
242 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

971 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