c# - 使用 Xamarn android 和 SQLite 浏览器
问题描述
我是 Xamarn 和 C# 的新手,我尝试使用数据库制作应用程序。我尝试选择表格中的每一行并且它起作用了。但是当我尝试插入时,没有出现任何错误,但我看不到我在 SQLite browser 上添加的新行。此外,当我尝试选择所有行时,新的确实出现了:)。
我正在尝试创建一个数据库,如果有人添加了每个人都可以看到的项目,那么任何人都可以在其中添加他们可以看到的东西更像是商店。
还有一件事,当我尝试选择表时,我总是会收到此错误未处理的异常:Android.Database.Sqlite.SQLiteException:发生 在此处输入图像描述
这是我的联系
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Database.Sqlite;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Java.Interop;
using Java.Lang;
using SQLite;
using Boolean = System.Boolean;
using Byte = System.Byte;
using SQLiteException = SQLite.SQLiteException;
namespace AppDatabase.Resources
{
public class DBdiagnoseX : SQLiteOpenHelper
{
private static readonly string DB_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
private static string DB_name = "Diagnose.db";
private static int VERSION = 1;
public Context context;
public DBdiagnoseX(Context context) :base(context, DB_name, null, VERSION)
{
this.context = context;
}
public string GetSqlPath()
{
return Path.Combine(DB_path, DB_name);
}
public override SQLiteDatabase WritableDatabase
{
get
{
return CreateSQLiteDB();
}
}
private SQLiteDatabase CreateSQLiteDB()
{
SQLiteDatabase sqliteDB=null;
string path = GetSqlPath();
Stream streamSQLite = null;
FileStream streamWriter = null;
Boolean IsSQLiteInit = false;
try
{
if (File.Exists(path))
IsSQLiteInit = true;
else
{
streamSQLite = context.Resources.OpenRawResource(Resource.Raw.Diagnose);
streamWriter = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
if(streamSQLite!=null && streamWriter != null)
{
if(CopySQLiteDB(streamSQLite,streamWriter))
IsSQLiteInit = true;
}
}
if (IsSQLiteInit)
sqliteDB =SQLiteDatabase.OpenDatabase(path, null, DatabaseOpenFlags.OpenReadonly);
}
catch{ }
return sqliteDB;
}
解决方案
推荐阅读
- ffmpeg - ffmpeg 创建 mpeg-dash 块文件太慢导致 404 错误
- javascript - 我可以让我的不和谐机器人基于网站发送消息吗?
- reactjs - react redux中的删除操作不起作用
- postgresql - Postgres SERIALIZABLE Snapshot Isolation 出现意外的枢轴错误
- java - 从另一个类调用静态方法而不在 Java 中创建对象
- youtube - 如何批量删除所有 YouTube 评论
- json - 我的 JSON 是“有效的”,但在 SharePoint 列中不起作用
- javascript - 你能告诉我为什么下面的 javascript 代码并不总是在下面的简单 index.html 中出现吗?
- python - 如何在 Pandas 数据框中为索引添加列名
- npm - gulp-sass 5 没有默认的 Sass 编译器;请自己设置一个