. NET C # DataTable and DataSet objects detailed (1/3)

Source: Internet
Author: User

. 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;
}

Home 1 2 3 last

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.