如何:在 SQLite 查询中表示 NULL [英] How to: Representing NULL in SQLite queries

查看:97
本文介绍了如何:在 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 NULLIS NOT NULL.

You want to use IS NULL and IS NOT NULL when comparing equality/inequality to null.

这篇关于如何:在 SQLite 查询中表示 NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆