Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

empty resultset help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rodchar - 08 Mar 2008 06:30 GMT
hey all,
here's a snippet from my datalayer class:

da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(ds);      
dts = ds.Tables;

i was just wondering if the following is possible.
my problem is when the Fill returns no tables because much of the code was
designed to see at least one table. and i guess i could go around the code
checking for an empty table but i'd like to please get some other possible
ideas if i may.

such as, is it possible in sql side to return an empty row with the schema
thru a select statement or something?

or is there a way on the c# side to create the table and a blank row with
the schema seeing as the dataset is untyped?

i just would like to know if i can get a table with a blank row of the
schema if the .Fill method returns no tables.

thanks for any suggestions,
rodchar
Marc Gravell - 08 Mar 2008 08:44 GMT
Well, it depends a lot on what your SQL looks like...

You can get an empty row by running your existing SELECT, but with
"WHERE 1 = 0" or similar (i.e. returns zero rows, but includes the
schema metadata). There is also a SET FMTONLY ON/OFF statement, but I
don't recommend it in most circumstances (not least becaus it isn't
exactly portable).

It also depends on what your reasons are for a "fill" method that
doesn't do any SELECTs... it sounds to me like an error, so I would be
tempted to check for zero tables and throw an exception...

Marc
Marc Gravell - 08 Mar 2008 08:45 GMT
> an empty row
Sorry, I meant an empty results grid... no row ;-p
DDD - 08 Mar 2008 14:02 GMT
> > an empty row
>
> Sorry, I meant an empty results grid... no row ;-p

That's easy.
You just need an union statement like this:
select  * from yourTable  where ...
UNION select '' as column1, '' as column2, ...
Marc Gravell - 08 Mar 2008 19:52 GMT
> You just need an union statement like this:
> select  * from yourTable  where ...
> UNION select '' as column1, '' as column2, ...

Warning: SQL Server 2005 gets very, very upset if you try to union
different data-types into the same ordinal.
rodchar - 09 Mar 2008 17:54 GMT
thanks everyone for the feedback,
rod.

> hey all,
> here's a snippet from my datalayer class:
[quoted text clipped - 20 lines]
> thanks for any suggestions,
> rodchar

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.