SQLiteCommand 的變數定義自行參考 SQLite.Net 的 Help
簡單的 login and 新增 table function 如下
public void LoginSqliteDatabase()
{
/// Set Database Root
string DatabaseRoot = "c:\\test.db";
/// Set Database Password
string DB_Password = "password";
/// Open Database
/// Version is sqlite version
SQLiteConnection cnn = new SQLiteConnection("Data Source="+ DatabaseRoot+";"+ "Version = 3; Password ="+DB_Password);
/// Open connect
cnn.Open();
/// Define SQLite Command object
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = cnn;
CreatExampleTable(cmd);
}
注意 login 若沒有設定密碼的話,也可以換為以下指令
SQLiteConnection cnn = new SQLiteConnection("Data Source="+ DatabaseRoot+";");
public void CreatExampleTable(SQLiteCommand cmd)
{
try
{
/// Set Creat table command
cmd.CommandText = "create table tbl(one, two)";
/// IF have exist show error message
cmd.ExecuteNonQuery();
}
catch
{
Console.WriteLine("error");
}
}
注意 creat table 指令也可以換為以下格式,定義更多資訊
cmd.CommandText = "CREATE TABLE [tbl] (int, teo nvarchar(20))";
沒有留言:
張貼留言