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.