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("ADODB.COMMAND")
Set objRS = CreateObject("ADODB.RECORDSET")
With objCmd
.CommandType = adCmdStoredProc
.CommandText = strSPName
.CommandTimeout = 0
.ActiveConnection = mobjConn
.Parameters.Refresh
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
.Parameters(intCount + 1) = vntPara(intCount)
Next
End If
Set objRS = .Execute()
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
vntPara(intCount) = .Parameters(intCount + 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(strProc, msqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
sqlCmd.Parameters.Add(vntPara.GetValue(intCount))
Next
End If
msqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
vntPara.SetValue(sqlCmd.Parameters.Item(intCount). Value,
intCount)
Next
End If
Catch ex As Exception
strError = ex.Message & "<BR>" & strProc & "<BR>"
If vntPara.GetLowerBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
strError = strError & CStr(vntPara.GetValue(intCount)) &
", "
Next
strError = Mid(strError, 1, Len(Trim(strError)) - 1)
End If
End Try
Return sqlReader
msqlConn.Close()
End Function 4 1412
"Win" <aa*@aaa.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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("ADODB.COMMAND")
Set objRS = CreateObject("ADODB.RECORDSET")
With objCmd
.CommandType = adCmdStoredProc
.CommandText = strSPName
.CommandTimeout = 0
.ActiveConnection = mobjConn
.Parameters.Refresh
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
.Parameters(intCount + 1) = vntPara(intCount)
Next
End If
Set objRS = .Execute()
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
vntPara(intCount) = .Parameters(intCount + 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(strProc, msqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
sqlCmd.Parameters.Add(vntPara.GetValue(intCount))
Next
End If
msqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
vntPara.SetValue(sqlCmd.Parameters.Item(intCount). Value,
intCount)
Next
End If
Catch ex As Exception
strError = ex.Message & "<BR>" & strProc & "<BR>"
If vntPara.GetLowerBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
strError = strError & CStr(vntPara.GetValue(intCount))
&
", "
Next
strError = Mid(strError, 1, Len(Trim(strError)) - 1)
End If
End Try
Return sqlReader
msqlConn.Close()
End Function
First off, in your .NET code there is no equivilent of
Parameters.Refresh
Which fills in the stored procedure parameters by querying the server. In
..NET the SqlCommandBuilder has equivilent functionality. In general you
should hard-code your stored procedure parameters into your application
code, but that's another issue.
David
Thanks a lot.
Could you please explain "In general you should hard-code your stored
procedure parameters into your application code, but that's another issue."
"David Browne" <davidbaxterbrowne no potted me**@hotmail.comwrote in
message news:#O*************@TK2MSFTNGP06.phx.gbl...
>
"Win" <aa*@aaa.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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("ADODB.COMMAND")
Set objRS = CreateObject("ADODB.RECORDSET")
With objCmd
.CommandType = adCmdStoredProc
.CommandText = strSPName
.CommandTimeout = 0
.ActiveConnection = mobjConn
.Parameters.Refresh
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
.Parameters(intCount + 1) = vntPara(intCount)
Next
End If
Set objRS = .Execute()
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
vntPara(intCount) = .Parameters(intCount + 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(strProc, msqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
sqlCmd.Parameters.Add(vntPara.GetValue(intCount))
Next
End If
msqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
vntPara.SetValue(sqlCmd.Parameters.Item(intCount). Value,
intCount)
Next
End If
Catch ex As Exception
strError = ex.Message & "<BR>" & strProc & "<BR>"
If vntPara.GetLowerBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
strError = strError &
CStr(vntPara.GetValue(intCount))
&
", "
Next
strError = Mid(strError, 1, Len(Trim(strError)) - 1)
End If
End Try
Return sqlReader
msqlConn.Close()
End Function
First off, in your .NET code there is no equivilent of
Parameters.Refresh
Which fills in the stored procedure parameters by querying the server. In
.NET the SqlCommandBuilder has equivilent functionality. In general you
should hard-code your stored procedure parameters into your application
code, but that's another issue.
David
Win,
In my idea are you in your original code returning a recordset, but what is
it that you think that you are returning in the new code?
That can be used if you bind it to an ASPNET DataGrid by the way, but I am
in doubt that it is your intention.
Cor
"Win" <aa*@aaa.comschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
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("ADODB.COMMAND")
Set objRS = CreateObject("ADODB.RECORDSET")
With objCmd
.CommandType = adCmdStoredProc
.CommandText = strSPName
.CommandTimeout = 0
.ActiveConnection = mobjConn
.Parameters.Refresh
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
.Parameters(intCount + 1) = vntPara(intCount)
Next
End If
Set objRS = .Execute()
If .Parameters.Count 0 Then
For intCount = LBound(vntPara, 1) To UBound(vntPara, 1)
vntPara(intCount) = .Parameters(intCount + 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(strProc, msqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
sqlCmd.Parameters.Add(vntPara.GetValue(intCount))
Next
End If
msqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
If vntPara.GetUpperBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
vntPara.SetValue(sqlCmd.Parameters.Item(intCount). Value,
intCount)
Next
End If
Catch ex As Exception
strError = ex.Message & "<BR>" & strProc & "<BR>"
If vntPara.GetLowerBound(0) >= 0 Then
For intCount = vntPara.GetLowerBound(0) To
vntPara.GetUpperBound(0)
strError = strError & CStr(vntPara.GetValue(intCount))
&
", "
Next
strError = Mid(strError, 1, Len(Trim(strError)) - 1)
End If
End Try
Return sqlReader
msqlConn.Close()
End Function
"Win" <aa*@aaa.comwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
Thanks a lot.
Could you please explain "In general you should hard-code your stored
procedure parameters into your application code, but that's another
issue."
Sure. A stored procedure is just a function. Discovering the procedure
parameters at runtime is basically "late binding". It's just bad form
because it's expensive and makes your code harder to read and debug.
David This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: nanookfan |
last post by:
Hi all,
I'm having a bizarre problem converting XML files to HTML using an
XSLT. The problem is only occuring in my Netscape 7.0 browser. What
makes it more bizarre is that it is only...
|
by: Gary |
last post by:
Hi,
I am a Chinese student, I have a problem with the following code
//The follwing code in StaticSearch.h:
//
template <class Type> class dataList;
//
template <class Type> class Node ...
|
by: Harshit |
last post by:
I am working on socket programming, encountered a new and strange
problem today.
I am using #define PORT 80, before main(), and I am calling PORT in one
of the statments inside main(), I get an...
|
by: ASP newbie |
last post by:
I cannot run my asp.net application in w2k server.
But the program works fine under w2k professional.
Can anyone tell me is there any difference in the settings?
Many thanks.
|
by: luke.yolanda |
last post by:
Hi everybody,
Here is a problem about socket programming, please help me to solve it.
thanx!!
************************************************************
Implement a server-side program...
|
by: shonen |
last post by:
I'm currently attempting to connect to a shoutcast server
pull down the information from here and then I'll parse it.
I got this working with the httplib, which was great, the problem is I want...
|
by: programming |
last post by:
Hi all,
i have been having trouble with a login script that works on my
windows machine, however when i upload it to the Unix server through
VPN, the same script won't work! It won't parse...
|
by: Jerim79 |
last post by:
Here it is:
<?php
if($_SERVER=='POST'){
$Number=$_POST;
$Email=$_POST;
$Number2=0;
$error=0;
|
by: weidongtom |
last post by:
Hi,
I was submitting a solution of a certain problem to the online judge,
but it says my program is exceeding the time limit, I've been doing
some tweaks to my codes but still it didn't get me...
|
by: Bert |
last post by:
Problem is documented at http://ace.delos.com/usacoprob2?a=deAhyErCKsK&S=gift1
Why doesn't this work?
/*
ID: albert.4
LANG: C
TASK: gift1
*/
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |