How to use transaction?

  • Thread starter Thread starter TakeshiKitano
  • Start date Start date
T

TakeshiKitano

Guest
Hi all,

I am trying to use sqlite transaction, but somewhere is mistake. I have no idea where.


using (SQLiteConnection con = new SQLiteConnection(conString))

using (SQLiteTransaction trans = con.BeginTransaction())
{
try
{
using (SQLiteCommand cmd = new SQLiteCommand("delete from cars;", con, trans))
{
cmd.ExecuteNonQuery();
}
using (SQLiteCommand cmd = new SQLiteCommand("insert into cars (name) values ("peugeot");", con, trans))
{
cmd.ExecuteNonQuery();
}
trans.Commit();
}
catch (Exception ex)
{
MessageBox.Show("Commit Exception Type: " + ex.GetType() + "\n" + "Message: " + ex.Message);
try
{
trans.Rollback();
}
catch (Exception ex2)
{
MessageBox.Show("Rollback Exception Type: " + ex2.GetType() + "\n" + "Message: " + ex2.Message);
}
}
}

Continue reading...
 
Back
Top