Check Null Value in Select Query



Hi All,

I am using select query to create a additional data table but if no value is selected a error occurs “No Rows in Datatable”. How to check if the query is null or otherwise.


dbGeneralEntity = dbGeneralEntity.AsEnumerable().Where(Function (x) (x(“Company”).toString = “123” And x(“CustID”).toString = “abc”)=False).copytodatatable

Also if I have to give a variable in company and custid what will be the syntax

Abhinav kaushal


Hi @abhinav,

What you can do in this case is:

If (dbGeneralEntity.AsEnumerable().Where(Function (x) x(“Company”).toString <> “123” And x(“CustID”).toString <> “abc”).Any) Then
    dbGeneralEntity = dbGeneralEntity.AsEnumerable().Where(Function (x) x(“Company”).toString <> “123” And x(“CustID”).toString <> “abc”).Copytodatatable
End If

Using Variables:

If (dbGeneralEntity.AsEnumerable().Where(Function (x) Not x(“Company”).toString.Equals(numbersVar) And Not x(“CustID”).toString.Equals(lettersVar)).Any) Then
    dbGeneralEntity = dbGeneralEntity.AsEnumerable().Where(Function (x) Not x(“Company”).toString.Equals(numbersVar) And Not x(“CustID”).toString.Equals(lettersVar)).Copytodatatable
End If


Does .Any refers boolean return value here? @acaciomelo

Thanks in advance :slight_smile:



It works but you can also use .tolist() to check the count.