Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

'System.Data.DataSet' does not contain a definition for 'Any'

Posted on 2010-09-19
8
Medium Priority
?
2,360 Views
Last Modified: 2012-05-10
protected bool DataSourceIsEmpty(DataSet DataSource)
        {
            return DataSource == null || !DataSource.Any();
        }

Error      8      'System.Data.DataSet' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'System.Data.DataSet' could be found (are you missing a using directive or an assembly reference?)      C:\inetpub\wwwroot\OmegaLove.Web\OmegaLove.Web\Controls\UniGrid.ascx.cs      639      54      OmegaLove.Web
0
Comment
Question by:omegalove
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 2000 total points
ID: 33713326
A DataSet is not a single collection, it can contain several DataTables.

If you want to check if it contains no tables:

    DataSource.Tables.Count == 0

If you want to check that it contains one table, and that table is empty:

    DateSource.Tables.Count == 1 && DataSource.Tables[0].Rows.Count == 0
0
 

Author Comment

by:omegalove
ID: 33713359
I want to create a method to check if a datasource is empty.
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 2000 total points
ID: 33713531
Then you first have to define what you mean by empty in this case.

A DataSet can for example contain several tables, but all the tables are empty. Should the DataSet be considered to be empty or not?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:omegalove
ID: 33713566
Nothing null empty no rows.
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 2000 total points
ID: 33715301
A DataSet never contains any rows. It can only contain DataTables, which in turn can contain rows. So, you have to decide what it means when a DataSet is empty.

- Does it mean that it doesn't contain any tables?
- Does it mean that it contains one table, but that table is empty?
- Does it mean that it can contain several tables, but all tables are empty?
0
 

Author Comment

by:omegalove
ID: 33721443
       // Summary:
        //     Returns true if the given datasource is empty
        //
        // Parameters:
        //   dataSource:
        //     Datasource to check for emptyness
        public static bool DataSourceIsEmpty(object dataSource);

Not row count should = 0
what else?
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 2000 total points
ID: 33724781
If you want to accept Object as a data source, you first have to check it's type against types that you accept, and handle each type separately.

Something like:

public static bool DataSourceIsEmpty(object dataSource) {
  if (dataSource is IListSource) {
    IListSource source = dataSource as IListSource;
    if (source.ContainsListCollection) {
      return source.GetList().Count == 0;
    }
  }
  if (dataSource is IList) {
    return (dataSource as IList).Count == 0;
  }
  if (dataSource is ...) {
    ...
  }
  return true; // unknown types are considered empty sources
}

Open in new window

0
 

Author Closing Comment

by:omegalove
ID: 33762957
thanks.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

670 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