. Net C # detailed description of DataTable and DataSet objects (1/3)

Source: Internet
Author: User

. 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

Related Article

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.