本文整理汇总了C#中StoredProcedure.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# StoredProcedure.Execute方法的具体用法?C# StoredProcedure.Execute怎么用?C# StoredProcedure.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StoredProcedure
的用法示例。
在下文中一共展示了StoredProcedure.Execute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SP_Should_Execute_Without_Parameter2
public void SP_Should_Execute_Without_Parameter2()
{
StoredProcedure sp = new StoredProcedure("Ten Most Expensive Products", DataService.Providers["Northwind"]);
int count = 0;
using (IDataReader rdr =sp.GetReader())
{
while (rdr.Read())
count++;
rdr.Close();
}
sp.Execute();
Assert.IsTrue(count > 0);
}
示例2: TestTransaction
public void TestTransaction()
{
using (DbConnection connection = GetConnection())
{
connection.Open();
DbTransaction transaction = connection.BeginTransaction();
const string newName = "changed";
StoredProcedure changeName = new StoredProcedure("ChangeName");
changeName.Command.AddParameter("@Id", 2, DbType.Int32, 4);
changeName.Command.AddParameter("@NewName", newName, DbType.String, 50);
changeName.Execute(transaction);
StoredProcedure getName = new StoredProcedure("GetName");
getName.Command.AddParameter("@Id", 2, DbType.Int32, 4);
Assert.AreEqual(newName, getName.ExecuteScalar(transaction), "The name has not been changed");
transaction.Rollback();
Assert.AreEqual("name2", getName.ExecuteScalar(), "The name has not been reverted");
connection.Close();
}
}
示例3: SP_Outputs_DefaultProvider
public void SP_Outputs_DefaultProvider()
{
StoredProcedure sp = new StoredProcedure("SubSonicTestNW", DataService.GetInstance("Northwind"));
sp.Command.AddOutputParameter("@param");
sp.Execute();
//make sure there's outputs
Assert.IsTrue(sp.OutputValues.Count > 0);
//this SP just returns today's date.
//make sure it's right now!
DateTime dTest = Convert.ToDateTime(sp.OutputValues[0]);
Assert.IsTrue(dTest.Date == DateTime.Now.Date);
}
示例4: TestOutputParameterGeneric
public void TestOutputParameterGeneric()
{
StoredProcedure sp = new StoredProcedure("OutputParameter", "default");
sp.Command.AddParameter("@First", 2, DbType.Int32, 4);
sp.Command.AddParameter("@Second", 3, DbType.Int32, 4);
sp.Command.AddOutParameter("@Result", DbType.Int32, 4);
int result;
sp.Execute(out result);
Assert.AreEqual(5, result);
}