Solved

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

Posted on 2010-09-19
8
2,162 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
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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