Procedure or function “” expects parameter “”, which was not supplied

i am new on asp.net with vb.code behind

i am trying get value from 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.

Thanks in advance!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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, cekdatauploads is a strored procedure, you should declare it in the CommandType

esql.CommandType = CommandType.StoredProcedure
esql.CommandText = "cekdatauploads"
esql.Parameters.Add("@value", SqlDbType.Int, 2)
esql.Parameters("@value").Direction = ParameterDirection.Output
esql.ExecuteNonQuery()

Method 2

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()


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x