private void button2_Click(object sender, EventArgs e) { var foo = new foo(); foo.name = "Insert Test"; using (var session = GetFactory().OpenSession()) { using (var transaction = session.BeginTransaction()) { session.Insert(foo); transaction.Commit(); // foo.Id will now be set to the value generated by the database when the record was inserted. } } }
private void button2_Click(object sender, EventArgs e) { // Create a PetaPoco database object var db = new PetaPoco.Database("sqlite"); foo foo = new foo(); foo.name = "PetaPoco Insert Test"; try { db.Insert("foo", "Id", foo); } catch (Exception ex) { Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); } this.fooQuery1.Refresh(); }
private void button2_Click(object sender, EventArgs e) { foo foo = new foo(); foo.name = "Created by Dapper"; using (SQLiteConnection conn = GetSqlConnection()) { conn.Open(); string sqlQuery = "INSERT INTO foo(name) VALUES (@name)"; conn.Execute(sqlQuery, new { name="Created by Dapper"//foo.name }); conn.Close(); } this.fooQuery1.Refresh(); }
private void DoBackgroundWork_Insert(object sender, System.ComponentModel.DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; using (var session = GetFactory().OpenSession()) { using (var transaction = session.BeginTransaction()) { for (int i = 0; i < count; i++) { var foo = new foo(); foo.name = "MicroLite Insert Test " + i; session.Insert(foo); if (i % 500 == 0) worker.ReportProgress(i);//this.fooQuery1.AppendDisplay("."); } transaction.Commit(); } } }
private void DoBackgroundWork_Insert(object sender, System.ComponentModel.DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; // Create a PetaPoco database object var db = new PetaPoco.Database("sqlite"); using (var transaction = db.GetTransaction()) { for (int i = 0; i < count; i++) { foo foo = new foo(); foo.name = "PetaPoco Insert Test " + i; db.Insert("foo", "Id", foo); if (i % 500 == 0) worker.ReportProgress(i);//this.fooQuery1.AppendDisplay("."); } transaction.Complete(); } }