无法识别的令牌:“#” C# 到 SQLITE

本文关键字:SQLITE 识别 令牌 | 更新日期: 2023-09-27 18:37:24

背景 + 问题:

(乞丐在这里)我想用我的 c# 代码中的列表中的值填充 sqlite db。这是从finisarsqlite网站获取的sqlite代码: 我通过创建自己的列名(如"seq#"等)对其进行了一点修改。

但是我收到以下错误:"无法识别的令牌#"

也许我的语法是关闭的?

法典:

             // [snip] - As C# is purely object-oriented the following lines must be put     into a class:
        // We use these three SQLite objects:
        SQLiteConnection sqlite_conn;
        SQLiteCommand sqlite_cmd;
        SQLiteDataReader sqlite_datareader;
        // create a new database connection:
        sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
        // open the connection:
        sqlite_conn.Open();
        // create a new SQL command:
        sqlite_cmd = sqlite_conn.CreateCommand();
        // Let the SQLiteCommand object know our SQL-Query:
        sqlite_cmd.CommandText = "CREATE TABLE table1 (Seq# integer primary key, Field integer primary key, Description integer primary key);";
        // Now lets execute the SQL ;D                                                                                  
        sqlite_cmd.ExecuteNonQuery(); <<< ---- This is where Error Occurs !
        // Lets insert something into our new table:
        sqlite_cmd.CommandText = "INSERT INTO table1 (Seq#, Field, Description) VALUES (list[0], list[1], list[2]);";
        // And execute this again ;D
        sqlite_cmd.ExecuteNonQuery();

        // We are ready, now lets cleanup and close our connection:
        sqlite_conn.Close();
    }

无法识别的令牌:“#” C# 到 SQLITE

在 SQL 中,不能在纯标识符中使用#

您可以使用的是带引号的标识符。在SQL中,这是用双引号("Seq#")完成的。MySQL使用单引号('Seq#')或反引号(`Seq#`);SQL Server 使用括号 ( [Seq#] );为了兼容性,SQLite 支持所有这些。

如果不想在使用名称时引用该名称,请删除#