Check Null Value in Select Query

datatable

#1

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.

Query:

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

Regards
Abhinav kaushal


#2

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

#3

Does .Any refers boolean return value here? @acaciomelo

Thanks in advance :slight_smile:


#4

Hi

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

Cheers