-1
ALTER procedure [dbo].[carcallvalidation]
@carid nvarchar(100)=null
as 
begin
   select t.TBarcode, t.Paid,t.Status,t.DelDate from Transaction_tbl t where TBarcode=@carid
   declare @transid integer=null
   select @transid= t1.transactID from Transaction_tbl t1 where TBarcode=@carid
   select count(k.transactid) transid from KHanger_tbl k where k.transactid=@transid
end

在执行存储过程时,我会像这样退出:

Tbarcode   paid status
1111         0    2

Transid
2

如何在 vb.net 中获取 Transid 值?

我像这样获取第一行值:

 Dim cmdcarvalidation As New SqlCommand("carcallvalidation", con.connect)
 cmdcarvalidation.CommandType = CommandType.StoredProcedure
 cmdcarvalidation.Parameters.Add("@carid", SqlDbType.VarChar, 50, ParameterDirection.Input).Value = txtTicket.Text
 dr = cmdcarvalidation.ExecuteReader
 While dr.Read
    tbarcode=dr("Tbarcode")
    payd= dr("paid")
    status= dr("status")
 end while
4

1 回答 1

0

SqlDataReader.NextResult 方法

NextResult当您有多个结果集时,用于移动到下一个结果集 - 默认情况下,阅读器位于第一个结果集。

所以:

While dr.Read()
    tbarcode = dr("Tbarcode")
    payd = dr("paid")
    status = dr("status")
End While

dr.NextResult()

While dr.Read()
    transid = dr(0)
End While

dr.NextResult()

While dr.Read()
    transid_count = dr(transid)
End While

如果您只是想要存储过程中的第一个和第三个结果(跳过SELECT @transid结果集),您可以省略第二个dr.Read()

While dr.Read()
    ' process first result set
End While

dr.NextResult()
dr.NextResult()

While dr.Read()
    ' process the third result set
End While
于 2013-06-29T16:13:49.893 回答