sqldatasource 后台用代码,如何得到存储过程的返回值我的存储过程就是判断是否有这个帐号。有就执行一个 update语句,然后return 1我应该如何用代码实现得到这个返回值。请大家告诉我下,谢谢

解决方案 »

  1.   

    如果你的存储过程是output输出的,即:

    @ProductID int output
    返回值调用代码: SqlParameter P_ProductID=new SqlParameter("@ProductID",SqlDbType.Int,4);
    P_ProductID.Direction=ParameterDirection.Output;
    myCommand.Parameters.Add(P_ProductID); myConnection.Open();
    myCommand.ExecuteNonQuery();
    myConnection.Close(); ReturnID=(int)P_ProductID.Value;
    如果你的返回值不是OUTPUT,而是RETURN的
    那么用下面的方法:
    SqlParameter P_ProductID=new SqlParameter("@ProductID",SqlDbType.Int,4);
    P_ProductID.Value=ProductID;
    myCommand.Parameters.Add(P_ProductID); myConnection.Open();
    ReturnID=myCommand.ExecuteNonQuery();
    myConnection.Close();
      

  2.   

    要看你用的存储过程对应SqlDataSource的什么属性,我假设是UpdateCommand那么就在SqlDataSource的OnUpdated事件中处理    protected void SqlDataSource_Updated(object sender, SqlDataSourceStatusEventArgs e)
        {
             //这里参数的名称取决于你在前台存储过程返回值的名称
             //Label1.Text = e.Command.Parameters["@ReturnValue"].Value.ToString();
        }