Solved

VB.Net - Hold Variable Number of Items While Looping Through DataReader

Posted on 2015-01-02
4
112 Views
Last Modified: 2015-01-07
Good Day Experts and Happy New Year!

I have a new request for one of my projects today.  

While iterating through my DataReader I am inserting records into a SQL table.  Then at the end of the function I am sending and email out to Users before displaying a complete messageBox.  I need to be able to save each key value of the inserted records so I can send them in the body of the email.  The number of records will not be known.  The DataReader could have 5 or 50 or 100 or more to insert.  

So how can I save the primary key values of each record inserted so I can send later in the email?

Thanks for the insight,
jimbo99999
0
Comment
Question by:Jimbo99999
4 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 40527819
Are you generating your primary key on the client side, or is your database using an identity field? Are you inserting the records using a stored procedure, or are you building your SQL and then executing it for each row?
0
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40527842
Because you can read datareader only once, you can first store it in a variable (maybe array). Then use this variable value in your code to perform during the operation and when you need it for emailing.
0
 
LVL 32

Expert Comment

by:it_saige
ID: 40527936
It's going to depend upon how you do your insert.  If, when you insert the record, the row or field that contains the primary key is being returned (for example, using ExecuteScalar) you could insert this returned value into a collection; i.e. - a list or array.  You could then send out an email with the contents of this collection.

-saige-
0
 

Author Closing Comment

by:Jimbo99999
ID: 40535532
Thank you everyone for responding.  I tried eghtebas's suggestion and was able to get it working!

jimbo99999
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now