Solved

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

Posted on 2015-01-02
4
125 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

624 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