SKDas
SKDas

Reputation: 1

Display Message When No Data Found Using Linq to Sql using C#

I am very new to Linq & I am not getting how to show a message if the Linq query does not find any data in the Sql Table. e.g in ADO.Net We used to do like this

ADO.NET :-

    if(ds.Tables[0].Rows.count>0)

    {

    //Do Some Task

    }

    else

    {

    MessageBox.Show("No Data Found"); 

    }

LINQ TO SQL;-

    DataClasses1DataContext db = new DataClasses1DataContext();

    IQueryable<int> catalogNo = db.Product_Details.Select(p => p.pcatalog);

    if (What To Check Here?)

    {

    MessageBox.Show("No Data Found"); 

}

Can any one please help me? Thanks a ton in advance

Upvotes: 0

Views: 474

Answers (2)

Kokom
Kokom

Reputation: 1

catalogNo.Any() or catalogNo.Count() > 0

Upvotes: 0

Berto
Berto

Reputation: 664

You can use .Any()

if(catalogNo.Any()){
  //I have Data!!!
}else{
  //No data found
}

Upvotes: 2

Related Questions