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

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

2013-11-13 09:45:56  來源: .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-2013 電腦知識網 Computer Knowledge   All rights reserved.