- SqlCeCommand 构造函数 (String, SqlCeConnection, SqlCeTransaction
- ------------------
- string cmdText = "INSERT INTO FactSalesQuota " +
- "(EmployeeKey, TimeKey, SalesAmountQuota) " +
- "VALUES (2, 1158, 150000.00)";
- SqlCeConnection conn = new SqlCeConnection("Data Source =
- AdventureWorks.sdf;");
- conn.Open();
- // Start a local transaction; SQL Mobile supports the following
- // isolation levels: ReadCommitted, RepeatableRead, Serializable
- //
- SqlCeTransaction tx = conn.BeginTransaction
- (IsolationLevel.ReadCommitted);
- SqlCeCommand cmd = new SqlCeCommand(cmdText, conn, tx);
- try
- {
- cmd.ExecuteNonQuery();
- // Commit the changes to disk if everything above succeeded;
- // Use Deferred mode for optimal performance; the changes will
- // be flushed to disk within the timespan specified in the
- // ConnectionString 'FLUSH INTERVAL' property;
- //
- tx.Commit(CommitMode.Deferred);
- // Alternatively, you could use:
- // tx.Commit(CommitMode.Immediate);
- //
- // or use default (Deferred) commit mode:
- // tx.Commit()
- }
- catch (Exception)
- {
- // Handle errors here
- //
- tx.Rollback();
- }
- finally
- {
- conn.Close();
- }
占华