首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

带参数的update语句更新不了记录!解决思路

2012-01-24 
带参数的update语句更新不了记录!!!代码如下:strSQLupdateyhbsetmm@mmwhereid@id objCommandNewOleD

带参数的update语句更新不了记录!!!
代码如下:  
strSQL   =   "update   yhb   set   mm=@mm   where   id=@id "  
objCommand   =   New   OleDbCommand(strSQL,   objConnection)  
objCommand.Parameters.Add(New   OleDbParameter( "@id ",   OleDbType.VarChar,   50)).Value   =   strID  
objCommand.Parameters.Add(New   OleDbParameter( "@mm ",   OleDbType.VarChar,   50)).Value   =   strMM  
.ExecuteNonQuery()  


换成如下就可以了:  
strSQL   =   "update   yhb   set   mm= ' "&   strMM   & "   where   id= ' "&   strID   & " ' "  
objCommand   =   New   OleDbCommand(strSQL,   objConnection)  
objCommand.ExecuteNonQuery()

[解决办法]
public void Update(InfoEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append( "update T_Info set ");
strSql.Append( "Title=@Title, ");
strSql.Append( "Content=@Content, ");
strSql.Append( "KeyWord=@KeyWord, ");
strSql.Append( "DepartID=@DepartID, ");
strSql.Append( "Remark=@Remark, ");
strSql.Append( "DrafterName=@DrafterName, ");
strSql.Append( "DrafterTime=@DrafterTime, ");
strSql.Append( "Tel=@Tel, ");
strSql.Append( "State=@State ");
strSql.Append( "InfoClassID=@InfoClassID ");
strSql.Append( "InfoTypeID=@InfoTypeID ");
strSql.Append( " where InfoID=@InfoID ");
SqlParameter[] parameters = {
new SqlParameter( "@InfoID ", SqlDbType.Int,4),
new SqlParameter( "@Title ", SqlDbType.VarChar,300),
new SqlParameter( "@Content ", SqlDbType.VarChar,1000),
new SqlParameter( "@KeyWord ", SqlDbType.VarChar,200),
new SqlParameter( "@DepartID ", SqlDbType.VarChar,20),
new SqlParameter( "@Remark ", SqlDbType.VarChar,500),
new SqlParameter( "@DrafterName ", SqlDbType.VarChar,20),
new SqlParameter( "@DrafterTime ", SqlDbType.DateTime),
new SqlParameter( "@Tel ", SqlDbType.VarChar,20),
new SqlParameter( "@State ", SqlDbType.Int,4),
new SqlParameter( "@InfoClassID ", SqlDbType.Int,4),
new SqlParameter( "@InfoTypeID ", SqlDbType.Int,4)
};
parameters[0].Value = model.InfoID;
parameters[1].Value = model.Title;
parameters[2].Value = model.Content;
parameters[3].Value = model.KeyWord;
parameters[4].Value = model.DepartID;
parameters[5].Value = model.Remark;
parameters[6].Value = model.DrafterName;
parameters[7].Value = model.Tel;
parameters[8].Value = model.State;
parameters[9].Value = model.InfoClassID;
parameters[10].Value = model.InfoTypeID;

DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
}

热点排行