command object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, iam using vb.net code
this is my stored procedure in sql server.

create proc t1 (@q as int)
as
select * from test where id=@q

GO

------

i am using vb.net code below like this

Dim s As SqlClient.SqlDataReader
Me.SqlCommand1.Parameters("@RETURN_VALUE").Direction =
ParameterDirection.Output
Me.SqlCommand1.Parameters("@q").Value = 1
s = SqlCommand1.ExecuteReader
Do Until s.Read
MsgBox(s(0))
Loop

iam wondering how come iam not able to display msgbox, even though the data
is there.
any changes in the code need or
any changes in the stored procedure.

where should i change...

thanks
 
What are you trying to achieve here? I find your code very confusing.
Your stored procedure takes an input parameter and doesn't explicitly
set the return value, it simply returns a result set. You're setting
@q (the input parameter) as an output parameter. Since you don't have
SET NOCOUNT ON in the sproc, it also returns the rows affected, aka
the done in proc message.

--Mary
 
Do Until loops until the condition is true. So your loop is never entered
if s.Read() returns true, that is, there is data present.

Instead try Do While or simply a While loop which looks like

While s.Read()
' statements
End While
 
Back
Top