473,385 Members | 1,720 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,385 software developers and data experts.

C# & SQL Server

Hi all,

I have a table having 20 fields & 10 rows with one field as primary key
say rollNo.
I want to copy a row of the table to the table itself with a new
rollNo.

Is there a simple way out or i have to take the row in a dataset & then
modify the rollno column of the dataset with the new value & after that
write a insert query like:
insert into mytable values(dataset.Tables[0].Rows[0]["RollNo"],
dataset.Tables[0].Rows[0]["RollNo"],.....& so on).
The approach that i have written is a very cumbersome one..
also think of a table having 80 - 100 rows...unfortunately i have one
:-(

Kindly Help
Warm Regards
Sumit

Nov 17 '05 #1
1 1007
easiest way is to create a data adapter pointed at your table. Fill a
dataset using the data adapter, filtered as best you can to get as few rows
as possible.

Find the row you want to duplicate.

Then, using the rows and columns collections of the dataset, copy the value
of the old row to the new one. Catch and change the primary key column.

Then use the data adapter to write the updated dataset back, which will do
the complex insert statement for you.

The amount of code should be less than about 50 lines for a generic solution
you can reuse.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Sumit" <vo********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi all,

I have a table having 20 fields & 10 rows with one field as primary key
say rollNo.
I want to copy a row of the table to the table itself with a new
rollNo.

Is there a simple way out or i have to take the row in a dataset & then
modify the rollno column of the dataset with the new value & after that
write a insert query like:
insert into mytable values(dataset.Tables[0].Rows[0]["RollNo"],
dataset.Tables[0].Rows[0]["RollNo"],.....& so on).
The approach that i have written is a very cumbersome one..
also think of a table having 80 - 100 rows...unfortunately i have one
:-(

Kindly Help
Warm Regards
Sumit

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DC Gringo | last post by:
I have an image control (that pulls an image off an ESRI map server): <ASP:IMAGE ID="imgZonedCountry" RUNAT="server"></ASP:IMAGE> In the code behind I am setting the ImageURL to a String value...
2
by: JoRo | last post by:
Hi, I'm trying to add an onclick event to a button control so it will open up a new popup window. Everything works fine except where I add variables to pass on to the popup window. Where I have...
4
by: MLH | last post by:
A programmer developed an AMP (Apache/MySQL/PHP) application for me. When he was done, he sent me the PHP files and the MySQL dump file. Now, when I connect to the application on my LAN using...
2
by: Mehdi | last post by:
Hi, I need to pass an URL via a hidden value as follow: <input type="hidden" id="Test" runat="Server"> and on Page_Load I assign a value to this hidden input as follow: Test.Value =...
7
by: DC Gringo | last post by:
I am having a bear of a time with setting a URL query string as a text value in a dropdownlist and Server.URLEncode does not seem to do its job. theFullLink = theLinkPrefix &...
6
by: FoundThisOnline | last post by:
I have been searching online for a whole day and couldn't find an answer for this. I have this hyperlink server control: ------------------------------------------------ <asp:HyperLink...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
6
by: avcitamer | last post by:
We upgraded our system and problem below occured, pleas help me... Windows 2003 server SP1 When I set a decimal DB field value to "123,32" (using ADODB.recordset ) updated value was ok (123.32)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.