存储过程调用参数........ [英] stored procedure calling parameters ........

查看:67
本文介绍了存储过程调用参数........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储过程:

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代码:



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



它没有收集我的输出参数值...请解决此问题


添加的代码块-OriginalGriff [/edit]



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


[edit]Code blocks added - OriginalGriff[/edit]

推荐答案

在建立连接之前指定一个参数,等等.尝试更改顺序,我''从来没有见过如此做过.我也不确定参数是否更改,或者基础字符串值.

您的SQL应该在数据层中调用,并且控件应具有合理的名称.您如何跟踪label4是什么,label3是什么?
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 ?


这是一个很小的但是很重要的事情,您还是错过了. ExecuteReader应该被使用,而是ExecuteNonQuery.否则对我来说似乎很好.

干杯!

—MRB
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


您在哪里声明了myreader?

如果您声明,那就没关系.

后行

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


这篇关于存储过程调用参数........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆