PC Review


Reply
Thread Tools Rate Thread

Copying records from datatable to datatable in dataset

 
 
tshad
Guest
Posts: n/a
 
      24th Jun 2008
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


 
Reply With Quote
 
 
 
 
tshad
Guest
Posts: n/a
 
      24th Jun 2008
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" <(E-Mail Removed)> wrote in message
news:epH3%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix A DataTable named 'Tag2' already belongs to this DataSet.(XML/Datatable) frodenekkoy@hotmail.com Microsoft Dot NET 0 8th Jul 2008 08:14 AM
Copying datatable contents to another datatable VM Microsoft C# .NET 3 14th Jul 2004 07:31 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft Dot NET Framework 3 31st Oct 2003 01:05 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 2 31st Oct 2003 01:05 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 01:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:31 AM.