有没有什么简单的方法在ADO.net传存储过程参数时不必显式给出参数的名字?
ADO.net中调用带参数存储过程中,必需将参数名和参数值都添加进去,例如sqlCmd.Parameters.AddWithValue("@aa", obj);
这显得很不合理,以前在用ADO的时候可以只传值而不必显式给出参数名。

解决方案 »

  1.   

    我说一下我的解决方案,不知道是不是你想要的。
        可以先将参数封装起来,然后在传给数据库层的相应函数来处理,这样在直接调用存储过程时就看不到参数的任何信息。给一段自己写的代码。中间层是用Web Service来实现的,调用数据库层的函数。我将数据库层封装成一个类,在里面建立连接,创建SqlCommand,运行存储过程。
    [WebMethod]
    public bool DeleteStudent(string StudentID)
    {
        bool result ;
        try
       {
    StudentManager.DBClass.DBForSQL Db=new StudentManager.DBClass.DBForSQL  (ConfigurationSettings.AppSettings["SecurityConnection"]);
    System.Data.SqlClient.SqlParameter[] Para = new SqlParameter[1];
    Para[0] = new SqlParameter("@ID",SqlDbType.Char,10);
    Para[0].Value = StudentID;
    Db.RunProc("StuDeleteRecord",Para);
    Db.Close();
    result = true;
    return result;
         }
         catch
        {
    result = false;
    return result;
        }
    }
    public int RunProc(string procName, SqlParameter[] prams) 
    {
         SqlCommand cmd = CreateCommand(procName, prams);
         int numRowsAffected = cmd.ExecuteNonQuery();
         this.Close();         //return (int)cmd.Parameters["ReturnValue"].Value;
         return numRowsAffected;
    }
      

  2.   

    ADO可以很方便实现的东西为什么更加先进的ADO.NET反而不行了呢?