本人原来用的是SqlConnection 控件
,运行的时候是正常的,但换成SqlDataSource控件以后,不知道原来在SqlConnection正常运行的后面这两句如何改,指高人指点,原能正常运行的代码是这样的SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connString"]);
        conn.Open();        SqlCommand cmd = new SqlCommand("getdataset", conn);
        cmd.CommandType = CommandType.StoredProcedure;
... ....
cmd.Parameters.Add("@RecordCount", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.Parameters.Add("RowCount", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
我用SqlDataSource控件后,改成这样,发现出错 conn.SelectCommand = "getdataset";
 conn.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
....  ....错误信息如下:
编译错误 
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误消息: CS1502: 与“System.Web.UI.WebControls.ParameterCollection.Add(string, System.TypeCode, string)”最匹配的重载方法具有一些无效参数源错误:  行 178:                       conn.SelectParameters.Add("RecordCount", System.TypeCode.String, ParameterDirection.Output.ToString); 

解决方案 »

  1.   

    TypeCode 枚举指定对象的类型。如上述
    编译器错误消息: CS1502: 与“System.Web.UI.WebControls.ParameterCollection.Add(string, System.TypeCode, string)”System.Web.UI.WebControls.ParameterCollection.Add()的三个参数中第二个参数应为TypeCode类型, 而不应为字符串类型。
      

  2.   

    谢谢楼上回答,我按你的方法改成这样后,出现这样错误conn.SelectParameters.Add("RecordCount", System.TypeCode.String, ParameterDirection.Output.ToString());
    “/”应用程序中的服务器错误。
    --------------------------------------------------------------------------------将数据类型 nvarchar 转换为 int 时出错。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 将数据类型 nvarchar 转换为 int 时出错。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。