熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

VB.Net調用存儲過程並得到返回值

2022-06-13   來源: .NET編程 

  //存儲過程代碼

  CREATE PROCEDURE [AddNewInvoiceInfo] (@sUserID int@sClaimMethod varchar()@sInvoiceNum

  varchar()@sInvoiceDate datetime@sBuyCity varchar())AS

  Insert Into SMB_InvoiceInfo (MemberIDClaimMethodInvoiceNumInvoiceDateInvoiceCity) Values

  (@sUserID@sClaimMethod@sInvoiceNum@sInvoiceDate@sBuyCity)

  return @@IDENTITY

  GO

  //調用存儲過程代碼

  Dim CN As New SqlConnection()

  Dim InvoiceID As String

  Try

  CNConnectionString = DBConStr

  CNOpen()

  Dim CMD As SqlCommand

  CMD = New SqlCommand(AddNewInvoiceInfo CN)

  CMDCommandType = CommandTypeStoredProcedure

  CMDParametersAdd(New SqlParameter(@sUserID SqlDbTypeInt))

  CMDParameters(@sUserID)Value = CInt(UserIDText)

  CMDParametersAdd(New SqlParameter(@sClaimMethod SqlDbTypeVarChar ))

  CMDParameters(@sClaimMethod)Value = TransNameText

  CMDParametersAdd(New SqlParameter(@sInvoiceNum SqlDbTypeVarChar ))

  CMDParameters(@sInvoiceNum)Value = InvoiceNumText

  CMDParametersAdd(New SqlParameter(@sInvoiceDate SqlDbTypeDateTime))

  CMDParameters(@sInvoiceDate)Value = InvoiceDateSelectedDateDate

  CMDParametersAdd(New SqlParameter(@sBuyCity SqlDbTypeVarChar ))

  CMDParameters(@sBuyCity)Value = BuyCityText

  CMDParametersAdd(New SqlParameter(@sInvoiceID SqlDbTypeInt))

  CMDParameters(@sInvoiceID)Direction = ParameterDirectionReturnValue

  CMDExecuteNonQuery()

  InvoiceID = CMDParameters(@sInvoiceID)ValueToString()

  CMDDispose()

  Catch ex As Exception

  ResponseWrite(exToString())

  Finally

  CNClose()

  End Try


From:http://tw.wingwit.com/Article/program/net/201311/11528.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.