Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQlite连接中的非法字符(C#)_C#_Database_Sqlite - Fatal编程技术网

SQlite连接中的非法字符(C#)

SQlite连接中的非法字符(C#),c#,database,sqlite,C#,Database,Sqlite,我不熟悉SQL/SQLite,但当我尝试运行此方法搜索SQLite数据库时,它在con.Open()上失败,并说“系统参数异常:路径中的非法字符”。我已经试着去掉数据和源之间的空格,我也试着用C:小写。我正在使用Nuget包管理器中的SQLite private void searchDB(string search1, string search2) { //build connection to sqlite string cs = "Data Source=C:\flowD

我不熟悉SQL/SQLite,但当我尝试运行此方法搜索SQLite数据库时,它在con.Open()上失败,并说“系统参数异常:路径中的非法字符”。我已经试着去掉数据和源之间的空格,我也试着用C:小写。我正在使用Nuget包管理器中的SQLite

private void searchDB(string search1, string search2)
{
    //build connection to sqlite
    string cs = "Data Source=C:\flowData.db;Version=3;";
    using (SQLiteConnection con = new SQLiteConnection(cs))
    {
        con.Open();

        string stm = "SELECT * FROM  locationData";

        using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
        {
            using (SQLiteDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    string poll = rdr["FacilityName"].ToString();
                    if (poll.Contains(search1) || poll.Contains(search2))
                    {
                        searchResult.Items.Add(poll);
                    }
                }
            }
        }
        con.Close();
    }
}
错误:

看起来您需要避开反斜杠

string cs = "Data Source=C:\\flowData.db;Version=3;";
您还可以使用逐字记录字符串

string cs = @"Data Source=C:\flowData.db;Version=3;";

原始字符串中有一个
\f
字符,这是一个非法路径字符。

除了下面Chaospanion的答案之外,还有一个仅供参考的字符,以防您想知道字符串中的
\f
内容到底是什么:字符转义序列
\f
表示所谓的“表单提要”字符(ASCII十进制12,十六进制0x0C)。谢谢!我怎么会错过:)@wildBlue-我花了一点时间才记住。