我正在使用以下代码
创建数据库 oncreate
private void chech_database_exist_or_not()
{
string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "validation.db3");
bool exists = File.Exists(dbPath);
if (!exists)
SqliteConnection.CreateFile(dbPath);
var connection = new SqliteConnection("Data Source=" + dbPath);
connection.Open();
if (!exists)
{
// This is the first time the app has run and/or that we need the DB.
// Copy a "template" DB from your assets, or programmatically create one.
var commands = new[]{
"CREATE TABLE [user_detail] (_id integer NOT NULL PRIMARY KEY AUTOINCREMENT,user_name varchar,pass varchar,designation varchar,email varchar);",
"insert into user_detail(user_name,pass) values('testuser','testpass') "
};
foreach (var command in commands)
{
using (var c = connection.CreateCommand())
{
c.CommandText = command;
c.ExecuteNonQuery();
}
}
}
connection.Close();
}
在按钮上单击我调用下面的函数
private bool validate_user(string username, string password)
{
bool i;
i = true;
string str;
DataTable dt = new DataTable();
string dbPath1 = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "validation.db3");
SqliteConnection con = new SqliteConnection("Data Source=" + dbPath1);
str = "select pass from user_detail where user_name='" + username + "' and pass='" + password + "'";
SqliteCommand cmd = new SqliteCommand(str, con);
// SqliteDataAdapter da = new SqliteDataAdapter(cmd);
FillDatatable(cmd, dt);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
i = true;
}
else
{
i = false;
}
}
else
{
i = false;
}
return i;
}
我使用以下课程
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.OS;
using Mono.Data.Sqlite;
using System.Data;
using System.IO;
using Android.InputMethodServices;
谁能帮助我为什么会收到此错误以及如何克服它?