Solved

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

Posted on 2015-01-02
4
116 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 34

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 33

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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