look into SqlCommandBuilder or OleDbCommandBuilder 's DeriveParameters method, which populates the specified Command object's Parameters collection with parameter information for the stored procedure specified in the Command object

解决方案 »

  1.   

    ' 创建Connection和Command对象
      string strCnn  = "Data Source=.;Initial Catalog=zy;User Id=sa;Password=";
      SqlConnection myConnection =new SqlConnection(strCnn);
      SqlCommand myCommand=new SqlCommand("sp_person", myConnection);
      ' 使用存储过程
      myCommand.CommandType = CommandType.StoredProcedure;
      ' 向存储过程添加参数
      SqlParameter prmEmail= new SqlParameter("@PersonEmail", SqlDbType.VarChar, 255);
      prmEmail.Value = txtPersonEmail.Text;
      myCommand.Parameters.Add(prmEmail);  SqlParameter prmName=new SqlParameter("@PersonName", SqlDbType.VarChar, 255);
      prmName.Value = txtPersonName.Text;
      myCommand.Parameters.Add(prmName);
      myConnection.Open();
      myCommand.ExecuteNonQuery();
      myConnection.Close();
      

  2.   

    建立一个QueryObject,然后给每个参与存储过程参数的属性定义一个attribute:[参数名,类型,长度]
    在调用存储过程的时候,用Reflection来得到这个QueryObject的每个属性的对应SQL Parameter的名称,类型,值等等信息
    最后用楼上的方法建立SqlCommand对象