如何:在 SQLite 查询中表示 NULL

编程入门 行业动态 更新时间:2024-10-28 14:35:47
本文介绍了如何:在 SQLite 查询中表示 NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个使用 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

本文发布于:2023-10-20 03:48:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1509750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQLite   NULL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!