当前位置:网站首页>. 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); } } }
边栏推荐
- Programming language (1)
- [sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
- Mindmanager2022 serial number key decompression installer tutorial
- On my first day at work, this API timeout optimization put me down!
- Tkinter Huarong Road 4x4 tutorial III
- Pooling idea: string constant pool, thread pool, database connection pool
- 2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
- Rest参考
- DR-NAS26-Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-5GHz-high-power-Mini-PCIe-Wi-Fi-Module
- How can enterprises and developers take advantage of the explosion of cloud native landing?
猜你喜欢
How to connect a laptop to a projector
[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)
Covariance
[secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]
2 spark environment setup local
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
[SRS] build a specified version of SRS
This time, thoroughly understand bidirectional data binding 01
随机推荐
Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
Correlation
JS closure knowledge points essence
Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
Buuctf, web:[geek challenge 2019] buyflag
Analysis report on the development trend and Prospect of global and Chinese supercontinuum laser source industry Ⓚ 2022 ~ 2027
webAssembly
How to store null value on the disk of yyds dry inventory?
In 2022, 6G development has indeed warmed up
Flutter internationalized Intl
2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
Awk getting started to proficient series - awk quick start
Buuctf, misc: sniffed traffic
Plug - in Oil Monkey
How to restore the factory settings of HP computer
[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)
How does sentinel, a traffic management artifact, make it easy for business parties to access?
Mysql database - Advanced SQL statement (I)
The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)