Click here to Skip to main content
15,924,367 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
stored procedure:
create proc [dbo].[Sp_sample]
@code varchar(10),@name nvarchar(10) output ,@shortname nvarchar(10) output ,
@phone1 nvarchar(15) output ,@phone2 nvarchar(15) output ,@cell nvarchar(10) output ,@address1 nvarchar(40) output
as
begin
select @name=name,@shortname=shortname,@phone1=phone1,@phone2=phone2,@cell=cell,@address1=address1 from t_customermaster where code=@code
end


vb code:
Protected Sub Btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn.Click
con.Open()
       mycommand = New SqlCommand("sp_sample", con)
       mycommand.CommandType = CommandType.StoredProcedure
       Dim jparamater As New SqlParameter("@code", SqlDbType.VarChar, 20)
       jparamater.Direction = ParameterDirection.Input
mycommand.Parameters.Add(jparamater)
        jparamater.Value = tba.Text
 mycommand.CommandType = CommandType.StoredProcedure
        mycommand.Connection = con
        mycommand.CommandText = "sp_sample"
        mycommand.Parameters.Add("@name", SqlDbType.NVarChar)
        mycommand.Parameters("@name").Direction = ParameterDirection.Output
        mycommand.Parameters("@name").Value = Label1.Text
        mycommand.Parameters.Add("@shortname", SqlDbType.NVarChar)
        mycommand.Parameters("@shortname").Direction = ParameterDirection.Output
        mycommand.Parameters("@shortname").Value = Label2.Text
        mycommand.Parameters.Add("@phone1", SqlDbType.NVarChar)
        mycommand.Parameters("@phone1").Direction = ParameterDirection.Output
        mycommand.Parameters("@phone1").Value = Label3.Text
        mycommand.Parameters.Add("@phone2", SqlDbType.NVarChar)
        mycommand.Parameters("@phone2").Direction = ParameterDirection.Output
        mycommand.Parameters("@phone2").Value = Label4.Text
        mycommand.Parameters.Add("@cell", SqlDbType.NVarChar)
        mycommand.Parameters("@cell").Direction = ParameterDirection.Output
        mycommand.Parameters("@cell").Value = Label5.Text
        mycommand.Parameters.Add("@address1", SqlDbType.NVarChar)
        mycommand.Parameters("@address1").Direction = ParameterDirection.Output
        mycommand.Parameters("@address1").Value = lb1.Text
        con.Close()
        Try
            con.Open()
            myreader = mycommand.ExecuteReader()
            myreader.Close()
            MessageBox("Return Value : " & mycommand.Parameters("@name").Value)
        Catch ex As Exception
            MessageBox(ex.ToString())
        Finally
            con.Close()
        End Try
        'End Function
    End Sub


its not collected my output parameters values...please solve this problem


[edit]Code blocks added - OriginalGriff[/edit]
Posted
Updated 6-Jul-11 21:57pm
v2

You specify one parameter before you set up the connection, etc. Try changing the order, I've never seen it done that way before. I'm also not sure if the parameter gets changed, or the underlying string value.

your SQL should be called in a data layer, and your controls should have sensible names. How do you keep track of what label4 is, and what label3 is ?
 
Share this answer
 
v2
It's a small, but nevertheless important thing you missed. Not ExecuteReader should be used, but rather ExecuteNonQuery. Otherwise it seems fine to me.

Cheers!

—MRB
 
Share this answer
 
Where did you declare myreader?

If you declared, then its ok.

After the line

myreader = mycommand.ExecuteReader()


write

myreader = mycommand.ExecuteReader()

While myreader.Read()
             
           lblResult.text = lblResult.text + "\n" + reader(0);

End While



Accept the answer if found useful
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900