Knight Data Access Layer
ExecuteScalarSproc(String,Dictionary<String,Object>) Method
Example 




KellermanSoftware.NetDataAccessLayer Namespace > DataHelper Class > ExecuteScalarSproc Method : ExecuteScalarSproc(String,Dictionary<String,Object>) Method
The scalar stored procedure to execute
The parameters for the stored procedure
Execute the passed stored procedure and return the first column of the first row
Syntax
Public Overloads Overridable Function ExecuteScalarSproc( _
   ByVal storedProcedure As String, _
   ByVal parameters As Dictionary(Of String,Object) _
) As Object
Dim instance As DataHelper
Dim storedProcedure As String
Dim parameters As Dictionary(Of String,Object)
Dim value As Object
 
value = instance.ExecuteScalarSproc(storedProcedure, parameters)
public virtual object ExecuteScalarSproc( 
   string storedProcedure,
   Dictionary<string,object> parameters
)
public: virtual Object* ExecuteScalarSproc( 
   string* storedProcedure,
   Dictionary<string*,Object*>* parameters
) 
public:
virtual Object^ ExecuteScalarSproc( 
   String^ storedProcedure,
   Dictionary<String^,Object^>^ parameters
) 

Parameters

storedProcedure
The scalar stored procedure to execute
parameters
The parameters for the stored procedure

Return Value

The value from the stored procedure
Example
//Get the current thread static safe instance of the helper
SqlServerProvider provider = new SqlServerProvider();
 
//Specify User Name and License Key from the receipt, leave blank for trial mode
//db.UserName = "John Smith 1234";
//db.LicenseKey = "asdfl219==";
 
//Log to the console
db.EnableLogging();
 
//Open the database connection
db.OpenConnection();
 
//Parameters
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Years", "2");
 
string storedProcedure = "CalculateCustomerValue";
 
decimal results = Convert.ToDecimal(db.ExecuteScalarSproc(storedProcedure,parameters));
 
db.CloseConnection();
'Get the current thread static safe instance of the helper
Dim provider As New SqlServerProvider()
 
'Specify User Name and License Key from the receipt, leave blank for trial mode
'db.UserName = "John Smith 1234"
'db.LicenseKey = "asdfl219=="
 
'Log to the console
db.EnableLogging()
 
'Open the database connection
db.OpenConnection()
 
'Parameters
Dim parameters As New Dictionary(Of String, Object)()
parameters.Add("Years", "2")
 
Dim storedProcedure As String = "CalculateCustomerValue"
 
Dim results As Decimal = Convert.ToDecimal(db.ExecuteScalarSproc(storedProcedure,parameters))
 
db.CloseConnection()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DataHelper Class
DataHelper Members
Overload List