0
我使用如下代碼如何避免未處理的異常:System.EntryPointNotFoundException:在MonoDroid的
創建數據庫的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;
任何人都可以幫助我爲什麼我得到這個錯誤,我如何克服它?
那麼你喜歡哪個數據庫? – Vikky
您仍然可以使用SQLite,它是默認情況下在Android設備上發佈的唯一數據庫。問題不在於不支持SQLite,而是SQLite Android的*版本*不支持Mono提供程序使用的某些操作。您仍然可以使用ADO.NET,但不是全部。這篇文章可能會幫助你開始:http://www.gregshackles.com/2011/02/using-a-database-in-monodroid-applications/ –
我仍然有問題。我可以有任何示例項目顯示連接從單片機的sqlite連接? – Vikky