Jimbo99999
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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-
-saige-
ASKER
Thank you everyone for responding. I tried eghtebas's suggestion and was able to get it working!
jimbo99999
jimbo99999