使用OleDbParameter参数类需要注意参数顺序必须要和SQL文中此参数出现的顺序一致。例如更新一条数据:
/// <summary> /// 更新一条数据 /// </summary> public void Update(Maticsoft.Model.TContent model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TContent set "); strSql.Append("Title=@Title,"); strSql.Append("Author=@Author,"); strSql.Append("WebContent=@WebContent,"); strSql.Append("WriteDate=@WriteDate,"); strSql.Append(" where ID=@ID "); OleDbParameter[] parameters = { new OleDbParameter("@Title", OleDbType.VarChar,50), new OleDbParameter("@Author", OleDbType.VarChar,20), new OleDbParameter("@WebContent", OleDbType.VarChar,0), new OleDbParameter("@WriteDate", OleDbType.Date), new OleDbParameter("@ID", OleDbType.Integer,4)}; parameters[0].Value = model.Title; parameters[1].Value = model.Author; parameters[2].Value = model.WebContent; parameters[3].Value = model.WriteDate; parameters[4].Value = model.ID; DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); }假如把以上参数数组中的WriteDate和ID的前后顺序互换下,就不能更新成功。