首页 > 编程 > .NET > 正文

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

2024-07-10 12:57:16
字体:
来源:转载
供稿:网友
//存储过程代码
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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表