473,219 Members | 2,052 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,219 software developers and data experts.

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 6705
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.