DataSet, determining which table is empty

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I fill a DataSet by executing SQL-code like;

"select * from TableA where conditionA;
select * from TableA where conditionB;"

After Fill, my DataSet can contain 0 to 2 Tables. My problem is that
if the DataSet contains 1 Table, how can I tell which select-statement
returned the rows?
Did conditionA or conditionB result in 0 rows?

/Dan
 
Dan said:
I fill a DataSet by executing SQL-code like;

"select * from TableA where conditionA;
select * from TableA where conditionB;"

After Fill, my DataSet can contain 0 to 2 Tables. My problem is that
if the DataSet contains 1 Table, how can I tell which select-statement
returned the rows?
Did conditionA or conditionB result in 0 rows?


Yet another reason to fill your DataSets one table at a time, and to use
strongly-typed datasets.

But look at the DataTable's ExtendedProperties.

David
 
Dan,

This might not be the best possible solution for this case.

If you know the condition use the same condition to filter rows from the
table. Then you can do various comparisons like rowcount and then try some
more matching.

-SP
 
Ok, but the data might come from different tables. Lets say i fill
myDataSet with;
"select * from People where Region = 'A';
select * from Places where Region = 'B';"

I plan to use myDataSet.GetXml() and an xsl-file to present the data.
Therefore the tables in the myDataSet must have meaningfull names that I
can refer to in my xsl-file.
My problem is, how can I give the tables meaningfull names when
myDataSet might contain only one table and I dont konw which
sql-statement that returned rows and which did not.

If myDataSet contains two tables I can do as follows;
myDataSet.Tables(0).TableName = "People"
myDataSet.Tables(1).TableName = "Places"

But what should i do when myDataSet contains only one table?

/Dan
 
Dan,

When it is True or False we mostly test.
If Not True then we know that it is False.

When it is not people would it than probably be places?
Assuming as what you al the time write are 2 tables.

Cor
 
I'm sorry but I'm not following here..

When the result contains one table, what test would tell me if it's
Places or People? In both cases the one table is named "Table" after
Fill.

One way would be to look inside the table and by examining the column
names determining what table they belong to. A very poor solution.

Another way would be to rewrite my sql code like

"select '' as Name, '' as Region
union
select [Name], Region from People;"

(and similar for Places)

Also a very poor solution.

/Dan
 
Dan,

I was not sure of that, however than the best case is as normal is done, use
two fills and two dataadapters (or set the selectcommand) something like
this typed in this message, so there can be mistakes or typos

\\\
dim cmd as sqlcommand(conn, sqlstringPeople)
dim da as new sqldataadapter(cmd)
da.fill(ds, "People")
cmd.commandtext = sqlStringPlaces
da.fill(ds, "Places")
///
This was what David told you in the first place.

I hope this helps?

Cor
 
I'm afraid it does not help in this case :-)

My example is simplified. The sql code I will execute collects data from
10-15 different tables and it has to be done in a single batch (one
roundtrip) due to performance.

/Dan
 
My example is simplified. The sql code I will execute collects data from
10-15 different tables and it has to be done in a single batch (one
roundtrip) due to performance.
The fill uses the datareader row by row, so I do not see exactly where is
your performance benefit.

Cor
 
Back
Top