本文整理汇总了C#中StoredProcedure.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# StoredProcedure.ExecuteScalar方法的具体用法?C# StoredProcedure.ExecuteScalar怎么用?C# StoredProcedure.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StoredProcedure
的用法示例。
在下文中一共展示了StoredProcedure.ExecuteScalar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public static int Add(Seller item)
{
int newID = 0;
using (StoredProcedure sp = new StoredProcedure("Seller_AddItem"))
{
sp.Params.Add("@Name", System.Data.SqlDbType.DateTime).Value = item.Name;
newID = Convert.ToInt32(sp.ExecuteScalar());
}
return newID;
}
示例2: SP_ScalarTest
public void SP_ScalarTest()
{
StoredProcedure sp = new StoredProcedure("CustOrderHist", DataService.GetInstance("Northwind"));
sp.Command.AddParameter("@CustomerID", "ALFKI", DbType.AnsiString);
object result = sp.ExecuteScalar();
Assert.IsTrue(result != null);
}
示例3: 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();
}
}