471,348 Members | 1,288 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 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 6569
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Nathan Sokalski | last post: by
3 posts views Thread by mark blackall | last post: by
1 post views Thread by Ryan | last post: by
1 post views Thread by byrd48 | last post: by
6 posts views Thread by Lint Radley | last post: by
1 post views Thread by Ronak mishra | last post: by

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.