Solved

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

Posted on 2010-09-19
8
2,298 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 500 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 500 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

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

Assisted Solution

by:Göran Andersson
Göran Andersson earned 500 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

621 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