Solved

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

Posted on 2010-09-19
8
2,209 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
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 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
List<PaisEntity> - show some 1 37
insert value of checklistbox checked 4 39
Upgrade code from VS 2010 to VS 2015 7 32
asp.net figure out error 3 20
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

761 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