Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
923 views
in Technique[技术] by (71.8m points)

asp.net - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...