/// <summary> /// CREATE BLANK SQLITE DATABASE /// </summary> /// <param name="path"></param> static public void CreateTemplatesTable(string path) { if (System.IO.File.Exists(path)) { #if NCORE Console.Clear(); Console.Error.Write("File Exists...\n\"{0}\"", path); #else System.Windows.Forms.MessageBox.Show( string.Format("File Exists...\n\"{0}\"", path), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error ); #endif return; } using (System.IO.FileStream fs = System.IO.File.Create(path, 0)) { } using (SQLiteDb db = new SQLiteDb(path)) using (DataSet ds = db.Insert("templates", sql_create_templates, SelectTemplatesAdapter)) using (DataView v = ds.GetDataView("templates")) foreach (DataRowView rv in v) { // Templates.Add(TemplateElement.FromRowView(rv)); } }
void Event_ExecuteNonQuery(object sender, RoutedEventArgs args) { if (!database.IsLoaded) { return; } using (var db = new SQLiteDb(database.DataFile)) { try { data = db.Insert(edit.Text, DBInsert); } catch (Exception error) { ThrowException(error, queryError: true); } } }
public void InitializeDataFile() { using (SQLiteDb db = new SQLiteDb(datafile)) using ( DataSet ds = db.Insert( query_settingreset.Replace("@appname", ApplicationName), delegate( DbOp op, string q, SQLiteConnection c ) { SQLiteDataAdapter a = new SQLiteDataAdapter(); a.InsertCommand = new SQLiteCommand(q, c); return(a); })) {; } }
public static void Insert(string sSerialNo, string sCertData, string sCommonName, string sPwd) { string sConn = PlavyConfig.GetConnectionString("db"); SqlDb db = new SQLiteDb(sConn); var dbFactory = db.DbBuilder.DbFactory; var dbOperator = dbFactory.GetDbParamOperator(); db.BeginTransaction(); var obj = db.Insert <Certificate>(new Certificate() { SerialNo = sSerialNo, CommonName = sCommonName, CertData = sCertData, CertPwd = sPwd, Udt = DateTime.Now }); db.CommitTransaction(); }
/// <summary> /// 写入数据 /// </summary> public void Insert() { SqlDb db = new SQLiteDb(_connString); db.IsShowSqlToConsole = _isShowSqlToConsole; var dbFactory = db.DbBuilder.DbFactory; var dbOperator = dbFactory.GetDbParamOperator(); db.BeginTransaction(); db.IsShowSqlToConsole = _isShowSqlToConsole; for (int i = 1; i <= 20; i++) { db.Insert <UserInfo>(new UserInfo() { UserId = i, UserName = "******" + i.ToString(), Age = 110, Email = "joyet" + i.ToString() + "@qq.com" }); } db.CommitTransaction(); }
public setting SetValue(SQLiteDb db, setting value, bool force) { // first check if the value is present setting s = GetValue(db, value.Name, value.SType, value.Group); bool hasValue = s != null; if (force) { s.Value = value.Value; Logger.LogG("Force Value: ID", s.ID.ToString()); Logger.LogG("Force Value", s.Value); } string q = hasValue ? @"UPDATE [settings] SET [name] = @name, [type] = @type, [value] = @value, [desc] = @desc, [grp] = @grp, [gid] = @gid WHERE [id] = @xid;" : @"INSERT INTO [settings] ( [name],[type],[value],[desc],[grp],[gid] ) VALUES ( @name, @type, @value, @desc, @grp, @gid );"; // our insert statement if (hasValue) { using (DataSet ds = db.Update(Context.TableName, q, s.AdapterUpdate, s.FillOperation)) { if (ds.Tables.Count == 0) { } // else // if (ds.Tables[0].Rows.Count == 1) s = new setting(ds.Tables[Context.TableName].DefaultView[0]); } } else { using (DataSet ds = db.Insert(Context.TableName, q, s.AdapterInsert, s.FillOperation)) { // if (ds.Tables.Count==0) MessageBox.Show(q, "there wasn't a table!"); // else //if (ds.Tables[0].Rows.Count == 1) s = new setting(ds.Tables[Context.TableName].DefaultView[0]); } } return(s); }
/// <inheritdoc/> public override DataSet Insert(string q) { data.Tables.Clear(); using (SQLiteDb db = new SQLiteDb(datafile)) data = db.Insert(Context.TableName, q, AdapterInsert, FillInsert); return(data); }