找回密码
 注册
搜索
热搜: java php web
查看: 216|回复: 0

ASP.Net中使用VB.Net调用存储过程并得到返回值

[复制链接]
发表于 2009-1-26 06:31:08 | 显示全部楼层 |阅读模式
//存储过程代码
CREATE PROCEDURE [AddNewInvoiceInfo] (@sUserID int,@sClaimMethod varchar(50),@sInvoiceNum varchar(50),@sInvoiceDate datetime,@sBuyCity varchar(50))AS
Insert Into SMB_InvoiceInfo (MemberID,ClaimMethod,InvoiceNum,InvoiceDate,InvoiceCity) Values (@sUserID,@sClaimMethod,@sInvoiceNum,@sInvoiceDate,@sBuyCity)
return  @@IDENTITY
GO

//调用存储过程代码
Dim CN As New SqlConnection()
Dim InvoiceID As String
Try
    CN.ConnectionString = DBConStr
    CN.Open()
    Dim CMD As SqlCommand
    CMD = New SqlCommand("AddNewInvoiceInfo", CN)
    CMD.CommandType = CommandType.StoredProcedure

    CMD.Parameters.Add(New SqlParameter("@sUserID", SqlDbType.Int))
    CMD.Parameters("@sUserID").Value = CInt(UserID.Text)

    CMD.Parameters.Add(New SqlParameter("@sClaimMethod", SqlDbType.VarChar, 50))
    CMD.Parameters("@sClaimMethod").Value = TransName.Text

    CMD.Parameters.Add(New SqlParameter("@sInvoiceNum", SqlDbType.VarChar, 50))
    CMD.Parameters("@sInvoiceNum").Value = InvoiceNum.Text

    CMD.Parameters.Add(New SqlParameter("@sInvoiceDate", SqlDbType.DateTime))
    CMD.Parameters("@sInvoiceDate").Value = InvoiceDate.SelectedDate.Date

    CMD.Parameters.Add(New SqlParameter("@sBuyCity", SqlDbType.VarChar, 50))
    CMD.Parameters("@sBuyCity").Value = BuyCity.Text


    CMD.Parameters.Add(New SqlParameter("@sInvoiceID", SqlDbType.Int))
    CMD.Parameters("@sInvoiceID").Direction = ParameterDirection.ReturnValue

    CMD.ExecuteNonQuery()
    InvoiceID = CMD.Parameters("@sInvoiceID").Value.ToString()
    CMD.Dispose()
Catch ex As Exception
    Response.Write(ex.ToString())
Finally
    CN.Close()
End Try
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|软晨网(RuanChen.com)

GMT+8, 2024-11-23 01:01

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表