S
Shane
Hi all
Still trying to get my head around VB.Net/ADO.Net and have a question.
I can't work out how to 'process' a stored procedure multiple times.
In other words, in VB6/ADO I would do something like:
For i = 1 to 10
rs.Open "usp_Stored_Procedure '" & i & "'"
....process the results
rs.Close
Next
In essence, the recordset variable has been created and I am simply opening
and closing it a number of times with different input values to the Stored
procedure.
I think that I have started to get my head around 'easy' ADO.Net data
retrieval and can for instance open a data adapter and populate a data
table.
What I can't seem to establish is how to write the equivalent of the above
code in ADO.Net.
My program contains the following
Dim rs As New SqlDataAdapter(strSQL, myConnection)....where strSQL is a
Stored Procedure and accepts a parameter.
Dim rsTable As New Data.DataTable
rs.Fill(rsTable)
.....process the data
....and then I assume that I need to close the DataAdaptor (and Table)? i.e.
rs.Dispose()
rs = Nothing
rsTable.Dispose()
rsTable = Nothing
If I want to repeat this do I contain the whole code above within a loop, so
that the DataAdaptor and DataTable are continually being created, disposed
of and created again i.e. is the following accurate...?
'Start the Loop here
For i = 1 to 10
Dim rs As New SqlDataAdapter(strSQL, myConnection)
Dim rsTable As New Data.DataTable
rs.Fill(rsTable)
.....process the data
rs.Dispose()
rs = Nothing
rsTable.Dispose()
rsTable = Nothing
Next
The dataset will always only contain a single row - is there a better way to
process the above if data is limited to a single row each time?
Very many thanks for your consideration.
Shane Clark
Still trying to get my head around VB.Net/ADO.Net and have a question.
I can't work out how to 'process' a stored procedure multiple times.
In other words, in VB6/ADO I would do something like:
For i = 1 to 10
rs.Open "usp_Stored_Procedure '" & i & "'"
....process the results
rs.Close
Next
In essence, the recordset variable has been created and I am simply opening
and closing it a number of times with different input values to the Stored
procedure.
I think that I have started to get my head around 'easy' ADO.Net data
retrieval and can for instance open a data adapter and populate a data
table.
What I can't seem to establish is how to write the equivalent of the above
code in ADO.Net.
My program contains the following
Dim rs As New SqlDataAdapter(strSQL, myConnection)....where strSQL is a
Stored Procedure and accepts a parameter.
Dim rsTable As New Data.DataTable
rs.Fill(rsTable)
.....process the data
....and then I assume that I need to close the DataAdaptor (and Table)? i.e.
rs.Dispose()
rs = Nothing
rsTable.Dispose()
rsTable = Nothing
If I want to repeat this do I contain the whole code above within a loop, so
that the DataAdaptor and DataTable are continually being created, disposed
of and created again i.e. is the following accurate...?
'Start the Loop here
For i = 1 to 10
Dim rs As New SqlDataAdapter(strSQL, myConnection)
Dim rsTable As New Data.DataTable
rs.Fill(rsTable)
.....process the data
rs.Dispose()
rs = Nothing
rsTable.Dispose()
rsTable = Nothing
Next
The dataset will always only contain a single row - is there a better way to
process the above if data is limited to a single row each time?
Very many thanks for your consideration.
Shane Clark