Dear All,
I am going to change the coding from ASP & VB6 to ASP.Net and VB.Net.
However, there is no data retrieved after I changed the coding.
Is there anything wrong?
Thanks
=============== =============== =============== ===
VB6 coding
Public Function myRS(ByRef vntErr As Variant, ByRef vntErrDesc As Variant, _
ByVal strSPName As String, ParamArray vntPara()
As Variant) As ADODB.Recordset
On Error GoTo ErrorHandler
Dim intCount As Integer
Dim objCmd As Object
Dim objRS As Object
Set objCmd = CreateObject("A DODB.COMMAND")
Set objRS = CreateObject("A DODB.RECORDSET" )
With objCmd
.CommandType = adCmdStoredProc
.CommandText = strSPName
.CommandTimeout = 0
.ActiveConnecti on = mobjConn
.Parameters.Ref resh
If .Parameters.Cou nt 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
.Parameters(int Count + 1) = vntPara(intCoun t)
Next
End If
Set objRS = .Execute()
If .Parameters.Cou nt 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
vntPara(intCoun t) = .Parameters(int Count + 1)
Next
End If
End With
Set myRS = objRS
ProcExit:
Set objRS = Nothing
Set objCmd = Nothing
Exit Function
ErrorHandler:
vntErr = Err.Number
vntErrDesc = Err.Description
Resume ProcExit
End Function
=============== =============== =============== ===
..Net coding
=============== =============== =============== ===
Public Function myRS(ByRef strError As String, ByVal strProc As String,
_
ByVal ParamArray vntPara() As VariantType)
As SqlDataReader
Dim sqlReader As SqlDataReader
Dim intCount As Integer
Try
Dim sqlCmd As New SqlCommand(strP roc, msqlConn)
sqlCmd.CommandT ype = CommandType.Sto redProcedure
If vntPara.GetUppe rBound(0) >= 0 Then
For intCount = vntPara.GetLowe rBound(0) To
vntPara.GetUppe rBound(0)
sqlCmd.Paramete rs.Add(vntPara. GetValue(intCou nt))
Next
End If
msqlConn.Open()
sqlReader = sqlCmd.ExecuteR eader
If vntPara.GetUppe rBound(0) >= 0 Then
For intCount = vntPara.GetLowe rBound(0) To
vntPara.GetUppe rBound(0)
vntPara.SetValu e(sqlCmd.Parame ters.Item(intCo unt).Value,
intCount)
Next
End If
Catch ex As Exception
strError = ex.Message & "<BR>" & strProc & "<BR>"
If vntPara.GetLowe rBound(0) >= 0 Then
For intCount = vntPara.GetLowe rBound(0) To
vntPara.GetUppe rBound(0)
strError = strError & CStr(vntPara.Ge tValue(intCount )) &
", "
Next
strError = Mid(strError, 1, Len(Trim(strErr or)) - 1)
End If
End Try
Return sqlReader
msqlConn.Close( )
End Function
I am going to change the coding from ASP & VB6 to ASP.Net and VB.Net.
However, there is no data retrieved after I changed the coding.
Is there anything wrong?
Thanks
=============== =============== =============== ===
VB6 coding
Public Function myRS(ByRef vntErr As Variant, ByRef vntErrDesc As Variant, _
ByVal strSPName As String, ParamArray vntPara()
As Variant) As ADODB.Recordset
On Error GoTo ErrorHandler
Dim intCount As Integer
Dim objCmd As Object
Dim objRS As Object
Set objCmd = CreateObject("A DODB.COMMAND")
Set objRS = CreateObject("A DODB.RECORDSET" )
With objCmd
.CommandType = adCmdStoredProc
.CommandText = strSPName
.CommandTimeout = 0
.ActiveConnecti on = mobjConn
.Parameters.Ref resh
If .Parameters.Cou nt 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
.Parameters(int Count + 1) = vntPara(intCoun t)
Next
End If
Set objRS = .Execute()
If .Parameters.Cou nt 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
vntPara(intCoun t) = .Parameters(int Count + 1)
Next
End If
End With
Set myRS = objRS
ProcExit:
Set objRS = Nothing
Set objCmd = Nothing
Exit Function
ErrorHandler:
vntErr = Err.Number
vntErrDesc = Err.Description
Resume ProcExit
End Function
=============== =============== =============== ===
..Net coding
=============== =============== =============== ===
Public Function myRS(ByRef strError As String, ByVal strProc As String,
_
ByVal ParamArray vntPara() As VariantType)
As SqlDataReader
Dim sqlReader As SqlDataReader
Dim intCount As Integer
Try
Dim sqlCmd As New SqlCommand(strP roc, msqlConn)
sqlCmd.CommandT ype = CommandType.Sto redProcedure
If vntPara.GetUppe rBound(0) >= 0 Then
For intCount = vntPara.GetLowe rBound(0) To
vntPara.GetUppe rBound(0)
sqlCmd.Paramete rs.Add(vntPara. GetValue(intCou nt))
Next
End If
msqlConn.Open()
sqlReader = sqlCmd.ExecuteR eader
If vntPara.GetUppe rBound(0) >= 0 Then
For intCount = vntPara.GetLowe rBound(0) To
vntPara.GetUppe rBound(0)
vntPara.SetValu e(sqlCmd.Parame ters.Item(intCo unt).Value,
intCount)
Next
End If
Catch ex As Exception
strError = ex.Message & "<BR>" & strProc & "<BR>"
If vntPara.GetLowe rBound(0) >= 0 Then
For intCount = vntPara.GetLowe rBound(0) To
vntPara.GetUppe rBound(0)
strError = strError & CStr(vntPara.Ge tValue(intCount )) &
", "
Next
strError = Mid(strError, 1, Len(Trim(strErr or)) - 1)
End If
End Try
Return sqlReader
msqlConn.Close( )
End Function
Comment