如何从使用ADO的VB Select中获取值

时间:2015-03-09 09:00:56

标签: vb6 ado

我尝试从SQL Select中获取值,但它返回0.这是一个代码

Dim RS As ADODB.Recordset

On Error GoTo vbError

SetStoredProcedureValues RS, "pro_GetCustomerCount", DTMConn

 With dbComm
    .Parameters.Append .CreateParameter("@CompanyID", adVarChar, adParamInput, 5, strCompanyID)
    Set RS = .Execute
End With


If Not RS.EOF Then
    intAA = RS!intA
    intBB = RS!intB
End If

''cleanup
DestroyRS RS

Exit Function

这是程序

DECLARE @intA INT, @intB INT    
SELECT @intA = COUNT(txtNo) FROM tblCompany_Customer WHERE txtCompany = 'x' GROUP BY txtNo
SELECT @intB = COUNT(txtNo) FROM tblCompany_Customer1 WHERE txtCompany = 'x' GROUP BY txtNo

SELECT ISNULL(@intA, 0) AS intA, ISNULL(@intB, 0) AS intB

这是SetStoredProcedureValues

Public Function SetStoredProcedureValues(rsSP As ADODB.Recordset, strSP As String, Conn As ADODB.Connection)

Set dbComm = New ADODB.Command
Set dbParam = New ADODB.Parameter
Set rsSP = New ADODB.Recordset

With dbComm
    .ActiveConnection = Conn
    .CommandType = adCmdStoredProc
    .CommandText = strSP
    .CommandTimeout = 0
End With

End Function

当我运行pro_GetCustomerCount过程时,它返回两个值:
intA:55
intB:55
当我通过
从VB中的过程中检索值时 RS!intA或RS!intB,它们返回0.

我不知道为什么会这样。任何建议表示赞赏

0 个答案:

没有答案