. Net c # detailed description of datatable and dataset objects
A. For versions earlier than 1.6.1, the command can be obtained through the idbcommand attribute of requestscope, but the idbcommand attribute of 1.6.1 returns ibatisnet. datamapper. commands. dbcommanddecorator object. You can comment out the code to verify it.
B. The dbcommand objects returned by methods posted in some articles on the Internet are for splicing SQL statements, and the dbcommand for obtaining the stored procedure is not implemented (any parameter or parameter must be considered ). Based on the original data, this article tries to make improvements and currently supports SQL statements and stored procedures.
/// <Summary>
/// Obtain dbcommand, mainly for the stored procedure
/// </Summary>
/// <Param name = "sqlmapper"> </param>
/// <Param name = "statementname"> </param>
/// <Param name = "paramobject"> parameter </param>
/// <Param name = "dictparam"> parameter field </param>
/// <Param name = "dictparmdirection"> parameterdirection dictionary </param>
/// <Param name = "partition type"> </param>
/// <Returns> </returns>
Protected virtual idbcommand getdbcommand (isqlmapper sqlmapper, string statementname, object paramobject, idictionary dictparam, idictionary <string, parameterdirection> dictparmdirection, commandtype limit type)
{
If (partition type = commandtype. text)
{
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 (partition type );
Cmd. commandtext = request. idbcommand. commandtext;
If (partition type! = Commandtype. storedprocedure | dictparam = null)
{
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;
}
1 2 3