. NET C # DataTable and DataSet object detailed
A For previous versions of 1.6.1, the command can be obtained by Requestscope IDbCommand properties, but the IDbCommand property of version 1.6.1 Returns the Ibatisnet.datamapper.commands.dbcommanddecora Tor object, you can annotate the code to verify it.
B, some articles posted on the Internet to return the DbCommand objects are for the concatenation of SQL statements, no implementation to obtain the stored procedures DbCommand (with parameters without parameters to consider). Based on the original data, this paper attempts to make improvements, and currently supports SQL statements and stored procedures.
///<summary>
///get DbCommand, primarily for stored procedures
///</summary>
///<param name= "Sqlmapper" > </param>
///<param name= "Statementname" ></PARAM>
///<param name= "Paramobject" > Parameters </param>
///<param name= "Dictparam" > Parameter segment </param>
///<param name= "Dictparmdirection" >parameterdirection dictionary </param>
///<param name= "Cmdtype" ></PARAM>
///<returns> </returns>
Protected Virtual IDbCommand Getdbcommand (isqlmapper sqlmapper, String Statementname, Object Paramobject, IDictionary Dictparam, Idictionary<string, parameterdirection> dictparmdirection, CommandType Cmdtype)
{
if (cmdtype = = CommandType.Text)
{
& nbsp; return Getdbcommand (Sqlmapper, Statementname, Paramobject);
}
Istatement statement = sqlmapper.getmappedstatement (statementname). Statement;
Imappedstatement Maps Tutorial Tatement = sqlmapper.getmappedstatement (statementname);
Isqlmapsession session = new Sqlmapsession (sqlmapper);
if (sqlmapper.localsession!= null)
{
session = Sqlmapper.localsession;
}
Else
{
Session = Sqlmapper.openconnection ();
}
Requestscope request = Statement.sql.getrequestscope (Mapstatement, Paramobject, session);
Mapstatement.preparedcommand.create (Request, session as Isqlmapsession, statement, Paramobject);
IDbCommand cmd = Session.createcommand (Cmdtype);
cmd.commandtext = Request.idbcommand.commandtext;
if (cmdtype!= commandtype.storedprocedure | | dictparam = = NULL)
{
&nbs p; return cmd;
}
foreach (DictionaryEntry de in dictparam)//stored procedure
{
string key = De.key.tostring ();
IDbDataParameter dbparam = Cmd.createparameter ();
dbparam.parametername = key;
dbparam.value = de.value;
if (dictparmdirection!= null && dictparmdirection.containskey (key))
{
Dbparam.direction = Dictparmdirection[key]; ParameterDirection
}
Cmd.parameters.add (Dbparam);
}
return cmd;
}