简体   繁体   English

尝试创建表时,在Xamarin.Android中抛出SQLite.SQLiteException

[英]SQLite.SQLiteException thrown in Xamarin.Android when trying to create a table

I am trying to create a simple local SQLite database using Xamarin.Android. 我正在尝试使用Xamarin.Android创建一个简单的本地SQLite数据库。 The code for that is: 代码是:

string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
SQLiteConnectiondb = new SQLiteConnection (Path.Combine (folder, "Experimental.db"));
db.CreateTable<Employee>();

My Employee class is: 我的员工课程是:

[Table("Employees")]
    public class Employee
    {
        [PrimaryKey, AutoIncrement]
        int Id { get; set; }

        string Name { get; set; }

    }

The exception I am getting whenever the code reaches db.CreateTable is: 每当代码到达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>

To the inexperienced eyes of mine, this does look like an issue related to SQLite itself. 对于我没有经验的人来说,这看起来像是一个与SQLite本身相关的问题。 Has anyone else faced this and if so - what was your work-around? 有没有其他人面对这个,如果是这样 - 你的工作是什么?

Make the properties on the Employee class public so SQLite can see them when it's creating the columns for your table: 使Employee类的属性公开,以便SQLite在为表创建列时可以看到它们:

[Table("Employees")]
public class Employee
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public string Name { get; set; }

}

Problem is Linker Options, some times the SQLite-net package was not link with your project. 问题是链接器选项,有时SQLite-net包不与您的项目链接。 Have to check linker behaviour , in iOS link SDK assemblies only and mtouch : --linkskip=SQLite-net then its working. 必须检查链接器行为,仅在iOS链接SDK程序集和mtouch: - linkskip = SQLite-net然后它的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin sqLite.SQLiteException:使用两个数据库的约束 - Xamarin sqLite.SQLiteException: Constraint using two databases 无法在Xamarin.Android中创建SQLite数据库 - Can't Create SQLite Database in Xamarin.Android Xamarin.Android-使用SQLite.NET ORM创建多个数据库 - Xamarin.Android - Create Multiple Databases with SQLite.NET ORM sqlite-net-pcl {SQLite.SQLiteException:“附近”):语法错误 - sqlite-net-pcl {SQLite.SQLiteException: near “)”: syntax error Xamarin.Android尝试从资源加载样式时崩溃 - Xamarin.Android Crashes When Trying To Load Style From Resource xamarin.android尝试联系WCF时,“连接被拒绝” - “Connection refused” when xamarin.android is trying to contact WCF Xamarin.Android:SQLite-Net Extensions多对多 - 没有这样的表,NULL集合 - Xamarin.Android: SQLite-Net Extensions many-to-many - no such table, NULL collection 尝试调用新的 Fragment 页面时活动被破坏 - Xamarin.Android - Activity Destroyed when trying to call a new Fragment page - Xamarin.Android Xamarin.Android-来自SQLite的坐标未在Google地图上绘制 - Xamarin.Android -coordinates from SQLite are not drawn on Google maps 不支持在 xamarin.android 上使用 LINQ 连接 SQLite.Net 中的表 - Join tables in SQLite.Net with LINQ on xamarin.android is not supported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM