0

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

2 Answers 2

2

You can use .Any()

if(catalogNo.Any()){
  //I have Data!!!
}else{
  //No data found
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.