当前位置:网站首页>. 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);
}
}
}边栏推荐
- Yyds dry goods inventory Spring Festival "make" your own fireworks
- Rest reference
- Kali2021.4a build PWN environment
- Yyds dry goods inventory Prometheus alarm Art
- Learning notes of raspberry pie 4B - IO communication (SPI)
- Firefox set up proxy server
- [dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
- [flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
- Covariance
- Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
猜你喜欢
![[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)](/img/6c/2d48d441fee1981a271319fd9f6c23.jpg)
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)

C deep anatomy - the concept of keywords and variables # dry inventory #

How to solve win10 black screen with only mouse arrow

Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
![[golang] leetcode intermediate - alphabetic combination of island number and phone number](/img/40/a664ea866ce355c1f5e9305fe91780.jpg)
[golang] leetcode intermediate - alphabetic combination of island number and phone number

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

Buuctf, misc: sniffed traffic

Morning flowers and evening flowers

Blue Bridge Cup -- guess age

Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
随机推荐
[Android reverse] use the DB browser to view and modify the SQLite database (copy the database file from the Android application data directory | use the DB browser tool to view the data block file)
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
JS Demo calcule combien de jours il reste de l'année
[sg function]split game (2020 Jiangxi university student programming competition)
This time, thoroughly understand bidirectional data binding 01
C3p0 connection MySQL 8.0.11 configuration problem
Report on the development strategy of China's engineering bidding agency and suggestions for the 14th five year plan Ⓙ 2022 ~ 2028
How does sentinel, a traffic management artifact, make it easy for business parties to access?
IPhone development swift foundation 08 encryption and security
Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
Sow of PMP
Programming language (1)
How about agricultural futures?
4 environment construction -standalone ha
Can you draw with turtle?
Programming language (2)
Sed、Awk
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
Learning notes of raspberry pie 4B - IO communication (SPI)