当前位置:网站首页>. 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);
}
}
}边栏推荐
- Druids connect to mysql8.0.11
- LeetCode 1647. Minimum deletion times of unique character frequency
- 3 environment construction -standalone
- Overview of Yunxi database executor
- Blue Bridge Cup -- guess age
- How to store null value on the disk of yyds dry inventory?
- LeetCode 540. A single element in an ordered array
- In 2022, 6G development has indeed warmed up
- LeetCode 1646. Get the maximum value in the generated array
- Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
猜你喜欢
![[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)](/img/29/543dce2f24130d22c1824385fbfa8f.jpg)
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)

How can enterprises and developers take advantage of the explosion of cloud native landing?

Cesium terrain clipping draw polygon clipping

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

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)

Correlation

Blue Bridge Cup -- Mason prime

Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)

Team collaborative combat penetration tool CS artifact cobalt strike

This time, thoroughly understand bidirectional data binding 01
随机推荐
pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
Sow of PMP
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?
Covariance
Is it safe and reliable to open an account and register for stock speculation? Is there any risk?
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
IPhone development swift foundation 09 assets
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
(POJ - 2912) rochambau (weighted concurrent search + enumeration)
webAssembly
Yyds dry goods inventory Prometheus alarm Art
[sg function] lightoj Partitioning Game
Team collaborative combat penetration tool CS artifact cobalt strike
Buuctf, web:[geek challenge 2019] buyflag
C3p0 connection MySQL 8.0.11 configuration problem
C deep anatomy - the concept of keywords and variables # dry inventory #
[sg function]split game (2020 Jiangxi university student programming competition)
1 Introduction to spark Foundation