Wrox Programmer Forums
|
BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 Databases by Thearon Willis; ISBN: 9780764588945
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2008, 01:49 PM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 'Repeat' a stored procedure

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


 
Old February 14th, 2008, 06:49 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Shane,

Have a look at the SaveTimeSheet function on page 462. This should help you do what you want to do.

Thearon





Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
Stored Procedure jezywrap SQL Server ASP 1 January 3rd, 2007 12:29 AM
Stored Procedure Help. midway11 SQL Language 3 November 20th, 2006 06:36 AM
Stored Procedure Help BukovanJ SQL Language 2 October 10th, 2006 08:02 AM
C# and stored procedure Msmsn C# 1 August 26th, 2003 11:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.