468,272 Members | 1,985 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Insert records into database based on query

I would like to insert multiple records into a table
based on a query returned from the same table. For
example a datareader returns 3 records containing the
following records

user1 file1 group1
user1 file2 group1

I would then like to insert records into the table based
on the datareader but change the last field to the
following

user1 file1 group2
user1 file2 group2

The final result in the table should then be
user1 file1 group1
user1 file2 group1
user1 file1 group2
user1 file2 group2

I have tried looping through the datareader and doing a
insert via executenonquery. I have also tried using a
dataset and adding to the dataset.

Any help with this issue will be much appreciated
Nov 17 '05 #1
3 1652
You haven't explained what the problem is with your solutions.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Andrew Bourne" <ab*****@cogeco.ca> wrote in message
news:0a****************************@phx.gbl...
I would like to insert multiple records into a table
based on a query returned from the same table. For
example a datareader returns 3 records containing the
following records

user1 file1 group1
user1 file2 group1

I would then like to insert records into the table based
on the datareader but change the last field to the
following

user1 file1 group2
user1 file2 group2

The final result in the table should then be
user1 file1 group1
user1 file2 group1
user1 file1 group2
user1 file2 group2

I have tried looping through the datareader and doing a
insert via executenonquery. I have also tried using a
dataset and adding to the dataset.

Any help with this issue will be much appreciated

Nov 17 '05 #2
Hi Kevin,

Thanks for responding. I have managed to sort out the
problem by returning the datareader results into a
sortedlist array. (The Keys are unique) I then iterate
through the sortedlist and insert the records into the
database.

Thanks

Andrew
-----Original Message-----
You haven't explained what the problem is with your solutions.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Andrew Bourne" <ab*****@cogeco.ca> wrote in message
news:0a****************************@phx.gbl...
I would like to insert multiple records into a table
based on a query returned from the same table. For
example a datareader returns 3 records containing the
following records

user1 file1 group1
user1 file2 group1

I would then like to insert records into the table based on the datareader but change the last field to the
following

user1 file1 group2
user1 file2 group2

The final result in the table should then be
user1 file1 group1
user1 file2 group1
user1 file1 group2
user1 file2 group2

I have tried looping through the datareader and doing a
insert via executenonquery. I have also tried using a
dataset and adding to the dataset.

Any help with this issue will be much appreciated

.

Nov 17 '05 #3
Hi Kevin,

Thanks for responding. I have managed to sort out the
problem by returning the datareader results into a
sortedlist array. (The Keys are unique) I then iterate
through the sortedlist and insert the records into the
database.

Thanks

Andrew
-----Original Message-----
You haven't explained what the problem is with your solutions.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Andrew Bourne" <ab*****@cogeco.ca> wrote in message
news:0a****************************@phx.gbl...
I would like to insert multiple records into a table
based on a query returned from the same table. For
example a datareader returns 3 records containing the
following records

user1 file1 group1
user1 file2 group1

I would then like to insert records into the table based on the datareader but change the last field to the
following

user1 file1 group2
user1 file2 group2

The final result in the table should then be
user1 file1 group1
user1 file2 group1
user1 file1 group2
user1 file2 group2

I have tried looping through the datareader and doing a
insert via executenonquery. I have also tried using a
dataset and adding to the dataset.

Any help with this issue will be much appreciated

.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Philip Boonzaaier | last post: by
6 posts views Thread by efgh | last post: by
8 posts views Thread by nano2k | last post: by
6 posts views Thread by rn5a | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.