Help with Parameterizing SQL Query for C# with possible null values
Posted
by Jhonny D. Cano -Leftware-
on Stack Overflow
See other posts from Stack Overflow
or by Jhonny D. Cano -Leftware-
Published on 2010-06-03T22:01:25Z
Indexed on
2010/06/03
22:04 UTC
Read the original article
Hit count: 199
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);
© Stack Overflow or respective owner