1.StringBuilder strSql = new StringBuilder();
            strSql.Append("update Users set ");
            strSql.Append("UserName='" + UserName + "',");
            strSql.Append("UserPwd='" + UserPwd + "'");
            strSql.Append(" where UserId=" + UserId + " ");
            return DbHelperOleDb.ExecuteSql(strSql.ToString()); 2.string strSql = "update Users set UserName=@UserName,UserPwd=@UserPwd where UserId=@UserId";
            OleDbParameter[] parameters = {
new OleDbParameter("@UserId",UserId),
new OleDbParameter("@UserName",UserName),
new OleDbParameter("@UserPwd", UserPwd)};
            return DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);为什么用第一种方法可以更新用第二种带有参数的sql语句就不能更新?没有错误就是不能更新?(Access中)?
到底有什么不同?

解决方案 »

  1.   


    2.string strSql = "update Users set UserName=@UserName,UserPwd=@UserPwd where UserId=@UserId";
      OleDbParameter[] parameters = {
    new OleDbParameter("@UserName",UserName),
    new OleDbParameter("@UserPwd", UserPwd),
    new OleDbParameter("@UserId",UserId)};
    把顺序搞一致就行了
      

  2.   

    一听你说就是没有钻研过Access
      

  3.   

    2楼已经说的很清楚了,ACCESS不认参数的名字,只认参数的顺序
      

  4.   

    string strSql = "update Users set UserName=@UserName,UserPwd=@UserPwd where UserId=@UserId";
      OleDbParameter[] parameters = {
    new OleDbParameter("@UserName",UserName),
    new OleDbParameter("@UserPwd", UserPwd),
    new OleDbParameter("@UserId",UserId)};
      return DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);