OracleParameter数组重复使用的问题
AdoHelper adoHelper = AdoHelper.CreateHelper(StarTech.News.Common.AppConfig.DBInstance);
StringBuilder strSql = new StringBuilder();
strSql.Append("update T_NEWS_SEND set ROOTDEPARTID=:ROOTDEPARTID,ROOTDEPARTNAME=:ROOTDEPARTNAME,");
strSql.Append("DEPARTID=:DEPARTID,DEPARTNAME=:DEPARTNAME,USERID=:USERID,USERNAME=:USERNAME,CREATEDATE=:CREATEDATE");
strSql.Append(" where NEWSID=:NEWSID and SENDORGID=:SENDORGID and ROOTDEPARTID IS NULL");
string newsID = Request.QueryString["recordID"].Trim();
string rootDepartID = this.RootDepartId;
string rootDepartName = this.RootDepartName;
string departID = this.DepartId;
string departName = this.DepartName;
string userID = this.UserId;
string userName = this.MemberName;
DateTime createTime = DateTime.Now;
OracleParameter[] parameters = new OracleParameter[]
{
new OracleParameter(":SENDORGID",OracleType.VarChar,40),
new OracleParameter(":NEWSID",OracleType.VarChar,40),
new OracleParameter(":ROOTDEPARTID",OracleType.VarChar,40),
new OracleParameter(":ROOTDEPARTNAME",OracleType.VarChar,40),
new OracleParameter(":DEPARTID",OracleType.VarChar,40),
new OracleParameter(":DEPARTNAME",OracleType.VarChar,40),
new OracleParameter(":USERID",OracleType.VarChar,40),
new OracleParameter(":USERNAME",OracleType.VarChar,40),
new OracleParameter(":CREATEDATE",OracleType.DateTime)
};
parameters[1].Value = newsID;
parameters[2].Value = rootDepartID;
parameters[3].Value = RootDepartName;
parameters[4].Value = departID;
parameters[5].Value = departName;
parameters[6].Value = userID;
parameters[7].Value = userName;
parameters[8].Value = createTime;
//如果包含送达到人的公告
parameters[0].Value = this.UserId;
adoHelper.ExecuteSqlNonQuery(strSql.ToString(), parameters);
//如果包含送达到部门的公告
parameters[0].Value = this.DepartId;
adoHelper.ExecuteSqlNonQuery(strSql.ToString(), parameters);
//如果包含送达到单位的公告
parameters[0].Value = this.RootDepartId;
adoHelper.ExecuteSqlNonQuery(strSql.ToString(), parameters);
为什么parameters不能被得复使用??Microsoft是怎么样考虑的??
[解决办法]
参数有点像指针,可分为输入、输出和输入输出,NEW了一个实例,多个会话在修改参数数据,不合理的
[解决办法]
用深拷贝
List<OracleParameter> list1 = new List<OracleParameter>();
foreach (var p in par)
{
list1.Add((OracleParameter)((ICloneable)p).Clone());
}