如何在sqlite中创建表,而不使用xamarin为Android应用程序编码



我想为酒店POS开发一个android应用程序。我使用xamarin和sqlite数据库。我以编程方式创建了一个表。

我的问题是:我怎么能创建一个表而不做编码:像有没有任何方法来创建一个表而不做编码,就像我们在SQL Server中手动创建而不做编码。

我使用SQLite Studio创建了数据库和表,但是我无法在我的应用程序中查看这些表。

如果你正在使用xamarin,并且你想要一个可移植的数据库,请查看https://developer.xamarin.com/guides/xamarin-forms/working-with/databases/,你将不得不在每个项目中添加一个类。droid . ios . windows,以便根据平台正确获取每个dbPath。

要查看你的表,你必须创建一个类来表示这些表,以便在链接中从db获取信息到应用程序。

此外,在SQLite中,当运行时调用sqliteconconnection . createdatabase ();在创建连接时指定的dataBase文件中创建表,如果不存在,如果存在并且没有错误,则只是确认与数据库建立了连接。希望对你有所帮助。

对于android应用程序,如果你没有经验,但想要实现localdb,我建议使用ORM。Sugar ORM使用起来很简单,而且效果很好。关于如何使用它的例子很容易理解。

http://satyan.github.io/sugar/

希望能有所帮助。

你可以用sqlitebrowser创建这个表,然后将你的sqlite文件添加到你的Android项目的资源文件夹中。

我认为你需要从那里复制这个来打开数据库并对它进行编辑,就像这样:

static void CopyDatabaseIfNotExists (string dbName = "YOURDATABASENAME.sqlite")
{
  var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), dbName);
    if (!File.Exists(dbPath))
    {
        using (var br = new BinaryReader (Application.Context.Assets.Open (dbName)))
        {
            using (var bw = new BinaryWriter (new FileStream (dbPath, FileMode.Create)))
            {
                byte [] buffer = new byte [2048];
                int length = 0;
                while ((length = br.Read (buffer, 0, buffer.Length)) > 0)
                {
                    bw.Write (buffer, 0, length);
                }
            }
        }
    }
}

最新更新