Solved

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

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

Author Comment

by:omegalove
ID: 33713566
Nothing null empty no rows.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now