473,473 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Copying records from datatable to datatable in dataset

Running on VS.net 2005,

I am trying to copy rows from my datatable to another datatable in the same
dataset.

The schema would be identical.

I need to make the table name "forms" as I am passing this dataset to
function that expects a dataset with a datatable in it.

I am loading up the dataset with my database information and then copying
the data row by row to the new datatable until the key changes then I would
pass the dataset to the function for processing. When done, I would clear
the datatable (not sure the best way to do this - but was looking as
Clear()).

I am getting errors trying to clone the table so that the schema will be the
same but I can't seem to get it to work. I get an error trying to clone to
may already set up table:

Property or indexer 'System.Data.DataTableCollection.this[string]'
cannot be assigned to -- it is read only

***************************************
ds.Tables.Add("Forms");
ds.Tables["Forms"] = ds.Tables["UnUsed"].Clone; <---- Error here

foreach (DataRow dr in ds.Tables["UnUsed"].Rows)
{
if (oldApsID == 0)
oldApsID = (int)dr["AppsID"];

if (oldApsID != (int)dr["AppsID"])
{
oldApsID = (int)dr["AppsID"];
ds.Tables["Tables"].Clear();
ds.Tables.Add("Forms");
ds.Tables["Forms"] = ds.Tables["UnUsed"].Clone; <--- same error
here
}

if(oldApsID == (int)dr["ApsID"])
{
ds.Tables["Forms"].ImportRow (dr);
}
}
*****************************************

I assume my syntax is incorrect, or you have to clone and create the table
at the same time.

But I can't seem to get it to work.

Thanks,

Tom
Jun 27 '08 #1
1 6724
Actually, Clone may not be what I am looking for.

What I want to do is create a table in my dataset this has the same columns
as my other table and then copy selected rows into the table (until a value
changes), then clear the table and do it again until I finish with the
original table.

Thanks,

Tom
"tshad" <ts***@dslextreme.comwrote in message
news:ep****************@TK2MSFTNGP05.phx.gbl...
Running on VS.net 2005,

I am trying to copy rows from my datatable to another datatable in the
same dataset.

The schema would be identical.

I need to make the table name "forms" as I am passing this dataset to
function that expects a dataset with a datatable in it.

I am loading up the dataset with my database information and then copying
the data row by row to the new datatable until the key changes then I
would pass the dataset to the function for processing. When done, I would
clear the datatable (not sure the best way to do this - but was looking as
Clear()).

I am getting errors trying to clone the table so that the schema will be
the same but I can't seem to get it to work. I get an error trying to
clone to may already set up table:

Property or indexer 'System.Data.DataTableCollection.this[string]'
cannot be assigned to -- it is read only

***************************************
ds.Tables.Add("Forms");
ds.Tables["Forms"] = ds.Tables["UnUsed"].Clone; <---- Error here

foreach (DataRow dr in ds.Tables["UnUsed"].Rows)
{
if (oldApsID == 0)
oldApsID = (int)dr["AppsID"];

if (oldApsID != (int)dr["AppsID"])
{
oldApsID = (int)dr["AppsID"];
ds.Tables["Tables"].Clear();
ds.Tables.Add("Forms");
ds.Tables["Forms"] = ds.Tables["UnUsed"].Clone; <--- same error
here
}

if(oldApsID == (int)dr["ApsID"])
{
ds.Tables["Forms"].ImportRow (dr);
}
}
*****************************************

I assume my syntax is incorrect, or you have to clone and create the table
at the same time.

But I can't seem to get it to work.

Thanks,

Tom


Jun 27 '08 #2

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

Similar topics

2
by: Nedu N | last post by:
Hi Techies, I am facing problem in copying content of table from a untyped dataset into to a table inside the typed dataset. I wanted to copy the data into typed dataset in order to ease the...
2
by: | last post by:
This should be simple, for someone... I have an access database and I want to copy records from one table in one db to another table in another Access db. I tried creating a dataset for both and...
5
by: Nathan Sokalski | last post by:
I am writing an ASP.NET application in which I need to copy DataRows from one DataTable to another. When I use code such as the following: temprows = nodes.Select("state='PA'")...
3
by: suresh | last post by:
frenz, i need to disable the add new record mode in datarid. i just want to modify the existing records in the grid...but i dont want to add new records..how do i do that? -suresh
7
by: Ryan | last post by:
OK, here's my setup. I have a treeview control that is populated with records from a Product table, and it allows "checking". This is used for my automatic notification system. Say a particular...
3
by: mark blackall | last post by:
Hi all, I am new to vb.net and I am trying to use the vb.net components, rather than relying on the VB6 compatibility stuff with which I am more familiar. However, I seem to have fallen at...
1
by: Ryan | last post by:
I have an instance of a Dataset on one form that I want to copy all records of a particular Datatable to another forms Datatable (same Dataset/table, etc). Any way to do this? I've been looking...
1
by: byrd48 | last post by:
Hi, am attempting to create a DataTable by copying a table from a data set, then filter the rows as follows: DataTable dt = DataSet1.Tables.Copy; DataRow dr = dt.Select("myexpression"); ...
6
by: Lint Radley | last post by:
Hi Everyone, I need an opinion here on storing data for a program I am working on the processes DICOM images. Essentially, my program stores 25-45 (it varies depending on the user) ranges of...
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
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.