Help with Parameterizing SQL Query for C# with possible null values
- by Jhonny D. Cano -Leftware-
Hello, people.
I need help with parameterizing this query.
SELECT *
FROM greatTable
WHERE field1 = @field1
AND field2 = @field2
The user should be able to search for any of the 2 fields, and the user also should be able to search if the field2 has null values.
var query = "theQuery";
var cm = new SqlCommand(cn, query);
cm.AddParameter("@field1", "352515");
cm.AddParameter("@field2", DBNull.Value);
// my DataTable here is having 0 records
var dt = GetTable(cm);