Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

15 Experts available now in Live!

Get 1:1 Help Now