/// <Summary>
/// Stored procedure execution function
/// </Summary>
/// <Param name = "strspname"> stored procedure name </param>
/// <Param name = "ht"> parameter information set </param>
/// <Param name = "strparameterarray"> array of parameter names to be returned </param>
/// <Returns> hashtable with returned values </returns>
Public void execstoredprocedure (string strspname, hashtable HT, string [] strparameterarray)
{
Sqlcommand comm = new sqlcommand (strspname, Conn );
Comm. commandtype = commandtype. storedprocedure;
Idictionaryenumerator htenumerator = Ht. getenumerator ();
While (htenumerator. movenext ())
Comm. Parameters. Add (htenumerator. Key. tostring (), htenumerator. value );
Foreach (string strparametername in strparameterarray)
Comm. Parameters [strparametername]. Direction = parameterdirection. output;
Try
{
Openconn (); // open the database link
Comm. executenonquery ();
}
Finally
{
Closeconn (); // closes the database link
}
Ht. Clear ();
Foreach (string strparametername in strparameterarray)
Ht. Add (strparametername, Comm. Parameters [strparametername]. value );
}
/// <Summary>
/// Stored procedure execution function
/// </Summary>
/// <Param name = "strspname"> stored procedure name </param>
/// <Param name = "ht"> parameter information set </param>
Public void execstoredprocedure (string strspname, hashtable HT)
{
Sqlcommand comm = new sqlcommand (strspname, Conn );
Comm. commandtype = commandtype. storedprocedure;
Idictionaryenumerator htenumerator = Ht. getenumerator ();
While (htenumerator. movenext ())
Comm. Parameters. Add (htenumerator. Key. tostring (), htenumerator. value );
Try
{
Openconn (); // open the database link
Comm. executenonquery ();
}
Finally
{
Closeconn (); // closes the database link
}
}
Call method:
Hashtable ht = new hashtable ();
Ht. Add ("@ variable_1", "parameter 1 ");
Ht. Add ("@ variable_2", "parameter 2 ");
Ht. Add ("@ variable_3", "parameter 3 ");
// With returned data
String [] variablelist = {"@ variable_2", "@ variable_3 "};
Execstoredprocedure ("Stored Procedure name", hashtable HT, variablelist );
// Return data in the key corresponding to hashtable HT
// No returned data
Execstoredprocedure ("Stored Procedure name", hashtable HT );
// The execstoredprocedure method is a method that is reloaded twice.