Mono.Data.Sqlite 语法
我需要使用 Sqlite,但是我的语法有问题(这就是异常告诉我的...),这是我的代码:
using System;
using System.Data;
using Mono.Data.Sqlite;
class MainClass
{
public static void Main (string[] args)
{
string connectionString = "URI=file:SqliteTest.db,version=3";
SqliteConnection conn = new SqliteConnection(connectionString);
conn.Open();
SqliteCommand dbcommand = new SqliteCommand(conn);
string sql_command = "CREATE TABLE transaction (" +
"id INTEGER PRIMARY KEY," +
"datetemps TEXT NOT NULL," +
"description TEXT NOT NULL);";
Console.WriteLine(sql_command);
dbcommand.CommandText = sql_command;
dbcommand.ExecuteNonQuery();
dbcommand.Dispose();
conn.Close();
}
}
这是我收到的异常:
Unhandled Exception: Mono.Data.Sqlite.SqliteException: SQLite error
near "transaction": syntax error
我习惯使用 MySql,它不是我第一次使用数据库,但这是我第一次遇到这种问题,我只是不明白问题是什么,为什么会出现“语法问题”。
感谢您的提示!
I need to use Sqlite, but there's a problem with my syntax (well that's what the Exception is telling me...), Here's my code:
using System;
using System.Data;
using Mono.Data.Sqlite;
class MainClass
{
public static void Main (string[] args)
{
string connectionString = "URI=file:SqliteTest.db,version=3";
SqliteConnection conn = new SqliteConnection(connectionString);
conn.Open();
SqliteCommand dbcommand = new SqliteCommand(conn);
string sql_command = "CREATE TABLE transaction (" +
"id INTEGER PRIMARY KEY," +
"datetemps TEXT NOT NULL," +
"description TEXT NOT NULL);";
Console.WriteLine(sql_command);
dbcommand.CommandText = sql_command;
dbcommand.ExecuteNonQuery();
dbcommand.Dispose();
conn.Close();
}
}
Here's the Exception I'm receiving:
Unhandled Exception: Mono.Data.Sqlite.SqliteException: SQLite error
near "transaction": syntax error
I'm used to use MySql and it's not the first time I'm working with DataBases, but it's the first time I got that kind of problem, I just can't figure out what's the problem, why there is a 'syntax problem'.
Thanks for your tips!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Transaction 是 SQLite 中的保留关键字。要将其用作对象名称,请用单引号或双引号、括号或反引号括起来:
请注意,括号和反引号不是标准 SQL,因此通常建议使用引号。
有关其他保留字的完整列表:http://www.sqlite.org/lang_keywords.html
Transaction is a reserved keyword in SQLite. To use it as an object name, surround it with single or double quotes, brackets, or backticks:
Note that brackets and backticks are not standard SQL, so quotes are generally recommended.
For a complete list of other reserved words: http://www.sqlite.org/lang_keywords.html