SqlConnection myConnection = new SqlConnection(myConnString);
myConnection.Open();SqlCommand myCommand = new SqlCommand();
SqlTransaction myTrans;
myTrans = myConnection.BeginTransaction();myCommand.Connection = myConnection;
myCommand.Transaction = myTrans;try
{ myCommand.CommandText = "Insert into Module (ID, Name) VALUES (5, 'Descr')";
myCommand.ExecuteNonQuery();
myTrans.Save("SampleTransaction"); myCommand.CommandText = "Insert into Module (ID, Name) VALUES (5, 'Descript')";
myCommand.ExecuteNonQuery();
myTrans.Commit();
Console.WriteLine("Both records are written to database.");
}
catch(Exception e)
{
try
{
myTrans.Rollback("SampleTransaction");
}
catch (SqlException ex)
{
if (myTrans.Connection != null)
{
Console.WriteLine("An exception of type " + ex.GetType() +
" was encountered while attempting to roll back the transaction.");
}
}
    
Console.WriteLine("An exception of type " + e.GetType() +
" was encountered while inserting the data.");
Console.WriteLine("Neither record was written to database.");
}
finally 
{
myConnection.Close();
}表Module 有两个字段,ID为主键,不允许重复值,我的理解是表里有一ID为5、NAME为Descr的记录,MSDN里这样讲的:“使用 Save 方法创建一个保存点,然后调用 Rollback 方法以回滚到保存点,而不是回滚到事务的起点。”但是表里没有该记录,事务已回滚到了开始,是不是我的理解错误?这个Save到底有什么用?谢谢!