当前位置:网站首页>. Net ADO splicing SQL statement with parameters
. Net ADO splicing SQL statement with parameters
2022-07-03 22:29:00 【Time chaser】
The first is DAL Code in the data access layer :
// Method of data update
public static int shuxing_update(s_passnature model)
{
string sql = "update s_passnature set [email protected]_name,[email protected]_content,[email protected]_shuxing,[email protected]_shiledaddress,[email protected]_cost,[email protected]_company,[email protected]_start,[email protected],[email protected] where [email protected]_id";
//sqlparameter Object to add
SqlParameter[] parameter = {
new SqlParameter("@pass_name",SqlDbType.VarChar,200),
new SqlParameter("@pass_content",SqlDbType.VarChar,5000),
new SqlParameter("@pass_shuxing",SqlDbType.VarChar,5000),
new SqlParameter("@pass_shiledaddress",SqlDbType.VarChar,5000),
new SqlParameter("@pass_cost",SqlDbType.Decimal),
new SqlParameter("@pass_company",SqlDbType.VarChar,100),
new SqlParameter("@is_start",SqlDbType.Int,4),
new SqlParameter("@remark",SqlDbType.VarChar,5000),
new SqlParameter("@operatorType",SqlDbType.VarChar,50),
new SqlParameter("@pass_id",SqlDbType.Int,4)
};
// Object Assignment
parameter[0].Value = model.pass_name;
parameter[1].Value = model.pass_content;
parameter[2].Value = model.pass_shuxing;
parameter[3].Value = model.shiledaddress;
parameter[4].Value = model.pass_cost;
parameter[5].Value = model.pass_company;
parameter[6].Value = model.is_start;
parameter[7].Value = model.remark;
parameter[8].Value = model.operatorType;
parameter[9].Value = model.pass_id;
return Common.DbHelperSQL.ExecuteSql(sql, parameter);
}
dbhelper The method in :
public static int ExecuteSql(string SQLString, params SqlParameter[] cmdParms)
{
using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
try
{
DbHelperSQL. PrepareCommand(cmd,connection,(SqlTransaction)null,SQLString,cmdParms);
int num = cmd.ExecuteNonQuery();
// Clean up resources must be released after each execution , Otherwise, the program may be blocked
cmd.Parameters.Clear();
return num;
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
conn.Close();
}
}
}
}
// Data validation statements with parameters need to call this method for validation
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, string cmdText, SqlParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = CommandType.Text;//cmdType;
if (cmdParms != null)
{
foreach (SqlParameter parameter in cmdParms)
{
if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
(parameter.Value == null))
{
parameter.Value = DBNull.Value;
}
cmd.Parameters.Add(parameter);
}
}
}边栏推荐
- What indicators should be paid attention to in current limit monitoring?
- Firefox set up proxy server
- The 14th five year plan and investment feasibility study report of China's industry university research cooperation Ⓧ 2022 ~ 2028
- Miscellaneous things that don't miss the right business
- string
- QGIS grid processing DEM data reclassification
- China's coal industry investment strategic planning future production and marketing demand forecast report Ⓘ 2022 ~ 2028
- Blue Bridge Cup -- guess age
- JS demo calculate how many days are left in this year
- Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
猜你喜欢

Blue Bridge Cup Guoxin Changtian MCU -- program download (III)

2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination

Pooling idea: string constant pool, thread pool, database connection pool

The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention

2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers

540. Single element in ordered array

How to solve win10 black screen with only mouse arrow

Preliminary analysis of smart microwave radar module

Quick one click batch adding video text watermark and modifying video size simple tutorial

webAssembly
随机推荐
Yyds dry goods inventory hands-on teach you to create a jigsaw puzzle using the canvasapi
This time, thoroughly understand bidirectional data binding 01
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
Summary of fluent systemchrome
Sed、Awk
Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
WiFi 2.4g/5g/6g channel distribution
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
(POJ - 2912) rochambau (weighted concurrent search + enumeration)
Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
AST (Abstract Syntax Tree)
How to solve the problem of computer networking but showing no Internet connection
Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
IDENTITY
The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention
股票炒股开户注册安全靠谱吗?有没有风险的?
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
JS closure knowledge points essence