Link to home
Start Free TrialLog in
Avatar of Jimbo99999
Jimbo99999Flag for United States of America

asked on

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

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
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

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?
ASKER CERTIFIED SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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-
Avatar of Jimbo99999

ASKER

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

jimbo99999