动软执行多条语句
Posted 吃回头草的马
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动软执行多条语句相关的知识,希望对你有一定的参考价值。
private bool Execute4NewsPublicTypes(int id, List<int> newsTypes) { bool ret = false; List<CommandInfo> strSqlNewsTypes = new List<CommandInfo>(); try { string delSql = "delete from T_ADM_NewsPublicTypes where [email protected] \n"; SqlParameter[] cmdParmsDel = new SqlParameter[1]; cmdParmsDel[0] = new SqlParameter("@ID ", id); strSqlNewsTypes.Add(new CommandInfo(delSql, cmdParmsDel)); foreach (var i in newsTypes) { string insertSql = "insert into T_ADM_NewsPublicTypes values (@ID, @Type) \n"; SqlParameter[] cmdParmsInsert = new SqlParameter[2]; cmdParmsInsert[0] = new SqlParameter("@ID ", id); cmdParmsInsert[1] = new SqlParameter("@Type ", i); strSqlNewsTypes.Add(new CommandInfo(insertSql, cmdParmsInsert)); } DbPortalHelper.ExecuteSqlTran(strSqlNewsTypes); ret = true; } catch (Exception) { ret = false; } return ret; }
public List<int> Query4NewsPublicTypes(int id) { List<int> ret = new List<int>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select NewsType from T_ADM_NewsPublicTypes where [email protected] \n"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4) }; parameters[0].Value = id; DataSet ds = DbPortalHelper.Query(strSql.ToString(), parameters); var dt = ds.Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { var strType = dt.Rows[i]["NewsType"].ToString(); if (!string.IsNullOrWhiteSpace(strType)) { ret.Add(int.Parse(strType)); } } return ret; }
以上是关于动软执行多条语句的主要内容,如果未能解决你的问题,请参考以下文章
.NET(C#) Dapper Oracle(ODP.NET)或SQL Server 执行多条查询(select)语句的方法代码