vb.net

位置:IT落伍者 >> vb.net >> 浏览文章

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


发布日期:2021年10月15日
 
VB.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

               

上一篇:VB.NET实现PC与掌上电脑PPC的双向通信

下一篇:如何建立一个VB.NET日期/时间值