473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1817
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
by: efgh | last post by:
I'm fairly confident in my knowledge of SQL but I'm stumped with regards with an Insert Into statement in Access 2003. I've got a 4 column table that I've simplified about as much as I can, no...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
5
by: Ferasse | last post by:
Hi, I'm an occasional Ms-Access developer, so there is still a lot of stuff that I don't get... Right now, I'm working on a database that stores contractual information. One of the form that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.