jeudi 11 octobre 2018

get all rows from db if parameter added to where clause is null

I have big select with where condition.

WHERE ADB.param1=@param

In Where I send param variable

        SqlParameter param1Param = cmd.Parameters.AddWithValue("@param1", param1);
        if (param1== null)
        {
            param1Param.Value = DBNull.Value;
        }

This code works the following way. When query executes it always checks for ADB.param1=param condition and when I send DBNull.Value it gets nothing from database. But instead of that I want that

if param== null

then it pay no attantion to this condition and get all rows from database. How can I achive that ?

Aucun commentaire:

Enregistrer un commentaire