我有一个使用 C# 编写的 SQLite 的数据库 winforms 应用程序.我正在尝试使用 C# 包装器执行一些 SQLite 查询,但是在我检查 NULL 值的查询中遇到了一些问题.这是调用语句.
I have a database winforms application using SQLite written in C#. I'm attempting to do some SQLite queries with the C# wrapper, but am having some issues with the query where I'm checking for NULL values. Here's the calling statement.
sqliteQuery.selectFromDatabase("*", "WHERE (FirstNotify = NULL) AND (SecondNotify != NULL) AND (ThirdNotify = NULL)");这是它背后的代码.
public DataTable selectFromDatabase(String column, String filter) { string SQL = "SELECT " + column + " FROM SUBCONTRACTOR " + filter; SQLiteCommand cmd = new SQLiteCommand(SQL); cmd.Connection = connection; SQLiteDataAdapter da = new SQLiteDataAdapter(cmd); DataSet ds = new DataSet(); try { da.Fill(ds); DataTable dt = ds.Tables[0]; return dt; } catch (Exception e) { MessageBox.Show(e.ToString()); return null; } finally { cmd.Dispose(); connection.Close(); } }查询根本没有返回任何内容,而本应返回几条记录.我是否正确处理了 NULL 检查?我发现了其他一些使用 WHERE (VAR IS NULL) 而不是使用 equals 的帖子.我已经尝试了这两种方法,但是我不确定当我使用IS"而不是equals"时如何处理not equals".任何人有任何见解?
The query is not returning anything at all, when it should be returning a few records. Am I handling the NULL checks correctly? I've found a few other posts that use WHERE (VAR IS NULL) instead of using equals. I've tried both, but am unsure as to how to handle "not equals" when I was using "IS" instead of "equals". Anyone have any insight?
谢谢!
推荐答案在将相等/不等式与 null 进行比较时,您希望使用 IS NULL 和 IS NOT NULL.
You want to use IS NULL and IS NOT NULL when comparing equality/inequality to null.
更多推荐
如何:在 SQLite 查询中表示 NULL
发布评论