本文整理汇总了C#中Utilities.SQL.SQLHelper.Rollback方法的典型用法代码示例。如果您正苦于以下问题:C# SQLHelper.Rollback方法的具体用法?C# SQLHelper.Rollback怎么用?C# SQLHelper.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utilities.SQL.SQLHelper
的用法示例。
在下文中一共展示了SQLHelper.Rollback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transaction
public void Transaction()
{
Guid TempGuid = Guid.NewGuid();
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.BeginTransaction();
Helper.AddParameter<string>("@StringValue1", "Test");
Helper.AddParameter<string>("@StringValue2", "Test");
Helper.AddParameter<long>("@BigIntValue", 123);
Helper.AddParameter<bool>("@BitValue", false);
Helper.AddParameter<decimal>("@DecimalValue", 1234);
Helper.AddParameter<float>("@FloatValue", 12345);
Helper.AddParameter<Guid>("@GUIDValue", Guid.NewGuid());
Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 1, 1));
Helper.ExecuteNonQuery();
Helper.Rollback();
Helper.BeginTransaction();
Helper.AddParameter<string>("@StringValue1", "Test String");
Helper.AddParameter<string>("@StringValue2", "Test String");
Helper.AddParameter<long>("@BigIntValue", 12345);
Helper.AddParameter<bool>("@BitValue", true);
Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m);
Helper.AddParameter<float>("@FloatValue", 12345.6534f);
Helper.AddParameter<Guid>("@GUIDValue", TempGuid);
Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31));
Helper.ExecuteNonQuery();
Helper.Commit();
}
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.ExecuteReader();
if (Helper.Read())
{
Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", ""));
Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", ""));
Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0));
Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false));
Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0));
Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0));
Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", Guid.Empty));
Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now));
}
else
{
Assert.Fail("Nothing was inserted");
}
}
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) as [ItemCount] FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.ExecuteReader();
if (Helper.Read())
{
Assert.Equal(1,Helper.GetParameter<int>("ItemCount",0));
}
else
{
Assert.Fail("Nothing was inserted");
}
}
}