当前位置:网站首页>. 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); } } }
边栏推荐
- Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
- 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
- [SRS] build a specified version of SRS
- On my first day at work, this API timeout optimization put me down!
- Pooling idea: string constant pool, thread pool, database connection pool
- Ansible common usage scenarios
- Morning flowers and evening flowers
- Harbor integrated LDAP authentication
- 股票炒股开户注册安全靠谱吗?有没有风险的?
- C3p0 connection MySQL 8.0.11 configuration problem
猜你喜欢
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
320. Energy Necklace (ring, interval DP)
Preliminary analysis of smart microwave radar module
Data consistency between redis and database
Firefox set up proxy server
Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
1068. Consolidation of ring stones (ring, interval DP)
Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
Awk getting started to proficient series - awk quick start
随机推荐
Buuctf, misc: sniffed traffic
JS demo calculate how many days are left in this year
How can enterprises and developers take advantage of the explosion of cloud native landing?
国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
How to restore the factory settings of HP computer
C3p0 connection MySQL 8.0.11 configuration problem
Analysis report on the development trend and Prospect of global and Chinese supercontinuum laser source industry Ⓚ 2022 ~ 2027
AST (Abstract Syntax Tree)
1 Introduction to spark Foundation
[automation operation and maintenance novice village] flask-2 certification
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
Miscellaneous things that don't miss the right business
Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
Es6~es12 knowledge sorting and summary
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD