Problem with a DataAdapter - Newbie Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

In the following code, I get an Error when I try to Fill the Dataset

String sql = "SELECT * FROM Table1 UNION SELECT * FROM Table2 UNION SELECT * FROM Table3"
SqlDataAdapter earnAggAdapter = new SqlDataAdapter(sql, con)
earnAggAdapter.Fill(tempDS, "Earnings"); // I get a "System Error" her

If I try with only the Union of Table1 and Table2 it works
Does that mean that the DataAdapter does not support more than one Union in the same statement
Is there another way to make this work

thanks

Jane
 
I think what's happening here is that the DataSet is only being bound to one
of the two data tables? Maybe you'll have to do it manually instead of using
Union, or use a stored procedure that somehow returns a single resultset.
 
There is nothing wront with such a concept and a three table union will work this way.

I belive you have a problem with a union itself and for some reason the server cannot union the three tables. Possible reasons are:
- one of the tables does not exist
- the tables' structures differ (different column names, different types, etc.)

Then there is a "System error" exception thrown.

Take your SQL and try to run it in the database using SQL Query Analyzer. You will find your problem quickly then.
 
Back
Top