积极答复者
SqlDatasource 调存储过程 无法取得Output参数

问题
-
ASPX代码:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:... %>" OldValuesParameterFormatString="original_{0}"
SelectCommand=...
UpdateCommand=...
DeleteCommand="Basic_DeleteEmployee"
DeleteCommandType="StoredProcedure" ondeleted="SqlDataSource1_Deleted" ondeleting="SqlDataSource1_Deleting">
<SelectParameters>
...
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="original_guid" Type="Object" DefaultValue="" />
<asp:Parameter Name="errorcode" Direction="InputOutput" Type="Int32" Size="4" DefaultValue="0"/>
<asp:Parameter Name="errortext" Direction="InputOutput" Type="String" Size="200" DefaultValue=" "/>
</DeleteParameters>
<UpdateParameters>
....
</UpdateParameters>
</asp:SqlDataSource>
存储过程:
CREATE PROCEDURE Basic_DeleteEmployee
@original_guid AS UNIQUEIDENTIFIER,
@errorcode AS INT = 0 OUTPUT,
@errortext AS NVARCHAR(2000) = '' OUTPUT
ASSql 2000监控:
exec Basic_DeleteEmployee @original_guid = '896817F2-CDAB-457B-AB9A-7817F44C055C', @errorcode = 0, @errortext = N' '
CS代码中:
protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
用e.Command.Parameters["@errorcode"].Value.ToString() 无法获得返回值
答案
-
你好!我试下了,默认的设置的确不能获取到返回值。但下面的方法是可以的。1 在 DeleteParameters 中去掉参数 errortext 的声明。2 在 Deleting 事件中重新声明参数 errortextprivate void SqlDataSource1_Deleting(Object sender, SqlDataSourceCommandEventArgs e){//定义新参数System.Data.SqlClient.SqlParameter p = new System.Data.SqlClient.SqlParameter("@errortext", System.Data.SqlDbType.Int);//定义参数p.Direction = System.Data.ParameterDirection.Output; //定义为输出参数e.Command.Parameters.Add(p);//给数据控件添加参数}
知识改变命运,奋斗成就人生!- 已标记为答案 KeFang Chen 2010年3月1日 4:03
全部回复
-
你好!我试下了,默认的设置的确不能获取到返回值。但下面的方法是可以的。1 在 DeleteParameters 中去掉参数 errortext 的声明。2 在 Deleting 事件中重新声明参数 errortextprivate void SqlDataSource1_Deleting(Object sender, SqlDataSourceCommandEventArgs e){//定义新参数System.Data.SqlClient.SqlParameter p = new System.Data.SqlClient.SqlParameter("@errortext", System.Data.SqlDbType.Int);//定义参数p.Direction = System.Data.ParameterDirection.Output; //定义为输出参数e.Command.Parameters.Add(p);//给数据控件添加参数}
知识改变命运,奋斗成就人生!- 已标记为答案 KeFang Chen 2010年3月1日 4:03
-
昏啊,高手再帮帮忙吧
我把Update 也改成这样,多了几个参数,一个Guid的,几个字符串的,但是出问题:不允许从数据类型 sql_variant 到 uniqueidentifier 的隐性转换。请使用 CONVERT 函数来运行此查询。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 不允许从数据类型 sql_variant 到 uniqueidentifier 的隐性转换。请使用 CONVERT 函数来运行此查询。
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
-
SQL 的监控
declare @P1 int
set @P1=NULL
declare @P2 nvarchar(200)
set @P2=NULL
exec Basic_Employee_Update @original_guid = '896817F2-CDAB-457B-AB9A-7817F44C055C', @deptid = N'0d00bdc8-0da1-4a41-85f4-1e06647ad2cc', @ename = N'Li **', @email = N'aaa', @phoneno = N'13800138000', @inuse = 1, @errorcode = @P1 output, @errortext = @P2 output
select @P1, @P2
go
@original_guid = '896817F2-CDAB-457B-AB9A-7817F44C055C'
@deptid = N'0d00bdc8-0da1-4a41-85f4-1e06647ad2cc'
因为这两个不一样?但这是原始的,没设置过啊