T
tshad
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
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