Lets imagine next situation, I am using ADO.NET Data Provider for SQLite, and want to select a user from SQLite db by his name and email (email is NULL).
using (var cmd = new SQLiteCommand(conn))
{
cmd.CommandText = "SELECT UserId FROM User WHERE Name=@Name and Email=@Email";
cmd.Parameters.AddWithValue("Name", userName);
cmd.Parameters.AddWithValue("Email", ((object)userEmail) ?? DBNull.Value);
var user = (int?)cmd.ExecuteScalar() ?? 0;
}
As the result I can't get existing user. The question is: Can I use DBNull.Value with SQLiteCommand?
You would end up with = NULL
which is not valid as nothing is equal to null.
How about ... WHERE Name=@Name and (Email=@Email or @Email IS NULL)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.