在存储过程sql 2008中声明变量
我正在从事一个使用存储过程的项目。当我尝试在项目中使用存储过程时,出现以下错误:在存储过程sql 2008中声明变量,sql,vb.net,sql-server-2008,stored-procedures,declare,Sql,Vb.net,Sql Server 2008,Stored Procedures,Declare,我正在从事一个使用存储过程的项目。当我尝试在项目中使用存储过程时,出现以下错误: The formal parameter "@Mode" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output. 请帮我解决这个问题 这是我的存储过程: alter PROCEDURE [ITAssets_sp_IT_Assets] -- Add the parameters for
The formal parameter "@Mode" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output.
请帮我解决这个问题
这是我的存储过程:
alter PROCEDURE [ITAssets_sp_IT_Assets]
-- Add the parameters for the stored procedure here
(@Mode varchar(12)='ADD',
@ID integer , @AssetCode nvarchar(20)=null, @Description nvarchar(70)=null,
@Site nvarchar(10)=null)
AS
Begin
IF @Mode='ADD'
Begin
Begin Tran
INSERT INTO [IT_Assets]
([ID]
,[AssetCode]
,[Description]
,[Site])
values
(@ID, @AssetCode, @Description, @Site
)
If @@ERROR <> 0
ROLLBACK TRAN
Else
COMMIT TRAN
Select @ID
End
ELSE
Begin
Begin Tran
UPDATE [IT_Assets]
SET
AssetCode = @AssetCode, Description = @Description, Site = @Site
WHERE ID = @ID
If @@ERROR <> 0
ROLLBACK TRAN
Else
COMMIT TRAN
Select @ID
End
End
AppExecuteQuery代码:
Public Shared Function AppExecuteNonQuery(ByVal SQLCommandType As CommandType, ByVal Command As String, Optional ByVal ParamTable As Hashtable = Nothing, Optional ByRef OutputParamTable As Hashtable = Nothing, Optional ByVal UsePrimaryConnection As Boolean = True, Optional ByVal ConnName As String = "", Optional ByVal ConnString As String = "") As Integer
Dim cmd As SqlCommand
Try
If UsePrimaryConnection Then
cmd = AppGetSQLCommand(SQLCommandType, Command, ParamTable, OutputParamTable, AppProperties.ConnectionString, True, UsePrimaryConnection, ConnName, ConnString)
Else
cmd = AppGetSQLCommand(SQLCommandType, Command, ParamTable, OutputParamTable, AppProperties.ConnectionString1, True, UsePrimaryConnection, ConnName, ConnString)
End If
Dim res As Integer = cmd.ExecuteNonQuery
For Each param As SqlParameter In cmd.Parameters
If param.Direction = ParameterDirection.Output Then
OutputParamTable(param.ParameterName) = param.Value
End If
Next
Return res
Finally
If Not cmd Is Nothing Then
If Not cmd.Connection Is Nothing Then
If cmd.Connection.State = ConnectionState.Open Then
cmd.Connection.Close()
End If
End If
End If
End Try
End Function
您的代码中包含以下内容:
AppExecuteNonQuery(CommandType.StoredProcedure, "IT_Assets", , ht)
由于ht
位于位置4,因此它被分配给OutputParamTable
,这将OUTPUT
参数添加到存储过程中。这也正是错误消息所说的
要修复它,请将其移动到位置3,即
AppExecuteNonQuery(CommandType.StoredProcedure, "IT_Assets", ht)
您如何调用存储过程?@shree.pat18问题编辑,您能否也共享
appexecutenoquery
方法的代码?错误似乎指向调用您的过程的语句有问题。它可能是标准化的,但这并不意味着它不是错误的来源。该错误明确表示“请求输出中传递的实际参数”-因此,我们需要查看生成实际参数的代码。@Damien\u不信者的答案已编辑我收到此错误不存在从对象类型System.Web.UI.WebControl.TextBox到已知托管提供程序本机类型的映射。
@7alhashmi-这是因为您添加的是txtDescription
txtDescription.Text
作为@Description
参数。@Damien\u异教徒谢谢!我错过了。
AppExecuteNonQuery(CommandType.StoredProcedure, "IT_Assets", ht)