我正在尝试使用 Xamarin.Android 创建一个简单的本地 SQLite 数据库。 代码是:
string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
SQLiteConnectiondb = new SQLiteConnection (Path.Combine (folder, "Experimental.db"));
db.CreateTable<Employee>();
我的员工类是:
[Table("Employees")]
public class Employee
{
[PrimaryKey, AutoIncrement]
int Id { get; set; }
string Name { get; set; }
}
每当代码到达 db.CreateTable 时我得到的异常是:
SQLite.SQLiteException: near ")": syntax error
at at SQLite.SQLite3.Prepare2 (intptr,string) <IL 0x0002c, 0x00160>
at at SQLite.SQLiteCommand.Prepare () <IL 0x00011, 0x0008f>
at at SQLite.SQLiteCommand.ExecuteNonQuery () <IL 0x00013, 0x000b3>
at at SQLite.SQLiteConnection.Execute (string,object[]) <IL 0x00041, 0x001ab>
at at SQLite.SQLiteConnection.CreateTable (System.Type,SQLite.CreateFlags) <IL 0x000a4, 0x005cb>
at at SQLite.SQLiteConnection.CreateTable<Core.Employee> (SQLite.CreateFlags) <0x00063>
在我没有经验的人看来,这看起来像是与 SQLite 本身有关的问题。有其他人遇到过这个问题吗?如果遇到过 - 您的解决方法是什么?
最佳答案
公开 Employee 类的属性,以便 SQLite 在为您的表创建列时可以看到它们:
[Table("Employees")]
public class Employee
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
}
关于c# - 尝试创建表时在 Xamarin.Android 中抛出 SQLite.SQLiteException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26243131/