vb.net 过程或函数“”需要未提供的参数“”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14772328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Procedure or function "" expects parameter "", which was not supplied
提问by Yan Susanto
i am new on asp.net with vb.code behind
我是asp.net的新手,后面有vb.code
i am trying get value from sql
我正在尝试从 sql 中获取价值
my code
我的代码
Dim apps As New MyApps
apps.OpenConnection()
Dim esql As New SqlCommand
esql.Connection = apps.oConn
esql.CommandText = "cekdatauploads"
esql.Parameters.Add("@value", SqlDbType.Int, 2)
esql.ExecuteNonQuery()
esql.Parameters("@value").Direction = ParameterDirection.Output
Dim nilai As Integer = esql.Parameters("@value").Value
apps.CloseConnection()
the error is
错误是
The parameterized query '(@value int)cekdatauploads' expects the parameter '@value', which was not supplied.
i already try execute store prosedure
我已经尝试执行商店程序
declare @p int
exec [cekdatauploads] @p output
print @p
and return 0 not empty value.
并返回 0 非空值。
Thanks in advance!
提前致谢!
回答by John Woo
try by interchanging the two lines.
尝试通过交换两条线。
esql.CommandText = "cekdatauploads"
esql.Parameters.Add("@value", SqlDbType.Int, 2)
esql.Parameters("@value").Direction = ParameterDirection.Output
esql.ExecuteNonQuery()
one more thing if, cekdatauploadsis a strored procedure, you should declare it in the CommandType
还有一件事,如果cekdatauploads是一个存储过程,你应该在CommandType
esql.CommandType = CommandType.StoredProcedure
esql.CommandText = "cekdatauploads"
esql.Parameters.Add("@value", SqlDbType.Int, 2)
esql.Parameters("@value").Direction = ParameterDirection.Output
esql.ExecuteNonQuery()
回答by GarethD
You are executing the procedure before you are telling the command that it is an output parameter, by default it assumes it is an input parameter.:
在告诉命令它是一个输出参数之前,您正在执行该过程,默认情况下它假定它是一个输入参数。:
esql.Parameters("@value").Direction = ParameterDirection.Output
esql.ExecuteNonQuery()

