public int adduser(string uname,string pwd,string tname,string borndate,string sex,string email,string question,string answer)
    {
        //int values = databasevalue != DBNull.Value ? (int)databasevalue : 0;
        object m_DBNull = Convert.DBNull;
        SqlParameter[] addnewuser ={
            new SqlParameter ("@uname",uname),
            new SqlParameter ("@pwd",pwd ),
            new SqlParameter ("@tname",tname),
            new SqlParameter ("@brondate",borndate),
            new SqlParameter ("@sex",sex),
            new SqlParameter ("@email",email ),
            new SqlParameter ("@question",question ),
            new SqlParameter ("@answer",answer),
            new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull)
        };
        try
        {
            database.executeNonQuery(database.str, CommandType.StoredProcedure, "addnewuser", addnewuser);
        }
        catch 
        {
            throw;
        }
        return Convert.ToInt32(addnewuser[8].Value);
    }

解决方案 »

  1.   

    new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull) 是这一句,有问题!
      

  2.   

    从错误提示来看:adduser只有8个参数,但是你调用的时候传递了9个参数,检查一下是不是这样。
      

  3.   

    adduser只有8个参数啊。
    new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull) 估计这句有问题
      

  4.   

    new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull)
    少写了一个参数~
      

  5.   

    new SqlParameter ()
    需要10个参数,你只传了9个。
      

  6.   

    new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull) 
    构造参数的时候,会忽略null的。可以看这里:http://www.svnhost.cn/Article/Detail-100.shtml
    这个可能是改版的了,你看看你自己的sqlhelper.cs吧。        private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
            {
                if( command == null ) throw new ArgumentNullException( "command" );
                if( commandParameters != null )
                {
                    foreach (SqlParameter p in commandParameters)
                    {
                        if( p != null )
                        {
                            // 检查未分配值的输出参数,将其分配以DBNull.Value.
                            if ( ( p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input ) && 
                                (p.Value == null))
                            {
                                p.Value = DBNull.Value;
                            }
                            command.Parameters.Add(p);
                        }
                    }
                }
            }
      

  7.   

    我晕了,
    给你个例子:
    IDataParameter[] parameters = new SqlParameter[9];
    parameters[0]=new SqlParameter("@tablename", SqlDbType.NVarChar,100);//表名
    parameters[1]=new SqlParameter("@fieldlist", SqlDbType.NVarChar,4000);//需要返回的列,默认为全部 
    parameters[2]=new SqlParameter("@orderfield", SqlDbType.NVarChar,100);//排序字段名
    parameters[3]=new SqlParameter("@keyfield", SqlDbType.NVarChar,100);//主键字段名
    parameters[4]=new SqlParameter("@pageindex", SqlDbType.Int);//页码,0开始
    parameters[5]=new SqlParameter("@pagesize", SqlDbType.Int);// 页尺寸
    parameters[6]=new SqlParameter("@strwhere", SqlDbType.NVarChar,4000);//查询条件 (注意: 不要加 where) 
    parameters[7]=new SqlParameter("@ordertype", SqlDbType.Bit);//排序,1,降序,0,升序
    parameters[8]=new SqlParameter("@Total", SqlDbType.Int);//返回记录总数, 非 0 值则返回  
    parameters[8].Direction=ParameterDirection.Output; parameters[0].Value=tablename;
    parameters[1].Value=fieldlist;
    parameters[2].Value=orderfield;
    parameters[3].Value=keyfield;
    parameters[4].Value=pageindex<0?0:pageindex;
    parameters[5].Value=pagesize;
    parameters[6].Value=strwhere;
    parameters[7].Value=ordertype=="ASC"?0:1;
    parameters[8].Value=Total;
    try
    {
    return DbHelperSQL.RunProcedure("proc_y_Sort_GetRecordFromPage",parameters,8,ref Total);
    }
    catch(Exception ex)
    {
    return null;
    }
      

  8.   

    new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull) 
    写那么多干什么把有用的写上就行了
    new SqlParameter("@result", SqlDbType.Int, 4, 跟个属性)
      

  9.   

    上面回复有误。不好意思。应该是new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull)这句。参数不匹配。
      

  10.   

    问题解决了。还是这一句有问题。new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,DataRowVersion .Default,m_DBNull)本来应该采用9个参数的。但我用了8个。我太粗心了。正确的为
    new SqlParameter ("@result",SqlDbType .Int,4,ParameterDirection.Output ,true,0,0,“”,DataRowVersion .Default,m_DBNull)