Sqlparameter array parameter passing Method

Source: Internet
Author: User
Http://caixiaodi51.blog.163.com/blog/static/139336285201011462415952/

 

 

Currently, the sqlparameter array-based parameter passing method is popular on the Internet. I have been using a high-level educational administration system, however, in this process, if you encounter many parameters that need to be returned (for example, there are dozens or even 20 parameters), it will be troublesome, it is especially painful to change the index value in the sqlparameter array when I suddenly don't need one of the dozens of parameters. so I made a slight change to make it easier for the corresponding parameters in the sqlparameter array. as follows,

Public static class publicvar
{
// Define operation Characters
Public static sqlcommand sqlcmd; // define command statements
Public static sqlparameter sqlparam; // define SQL Parameters
}

// Public Method
Public class publicmethod
{
// Complete SQL Parameters
Public sqlparameter param (string parametername, object parametervalue, sqldbtype dbtype)
{
// Instantiate
Publicvar. sqlparam = new sqlparameter ();
// Return the parameter name corresponding to the database
Publicvar. sqlparam. parametername = parametername;
// Parameter value
Publicvar. sqlparam. value = parametervalue;
// Parameter field type
Publicvar. sqlparam. sqldbtype = dbtype;
Return publicvar. sqlparam;
}

}

This is the case when referencing:


// Instantiate the BLL Layer
Public static goldcoincode_bll.publicmethod mymethod = new goldcoincode_bll.publicmethod ();


Public static datatable bll_select (string kabianhao_name1)
{
// Define an SQL parameter array and assign values to the parameter name, parameter value, and Parameter Field Type
Sqlparameter [] sqlcmdpas = {
Mymethod. Param ("@ Type", 1, sqldbtype. INT ),
Mymethod. Param ("@ kabianhao_name1", kabianhao_name1, sqldbtype. Char)
};
// Instantiate the class corresponding to the Dal layer, call the Dal class, and pass in Parameters
Datatable dt = goldcoincode_dal.publicmethod.dal_selectdb_par ("huiyuanguanli_select", sqlcmdpas );
Return DT;
}

Therefore, you do not need to correspond to the values in sqlparameter [] one by one, which is much easier.

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.