jackjohnson44
asked on
c# add datarow to another table
I am doing some updating/inserting into a table via a strongly typed dataset.
What I want to do with my function:
Check to see if a row exists in a database using a guid.
If it does, return that row.
If it doesn't, return a new row.
The problem is that after I return this row, I try to add it to my new dataset and update it. When I do, it says the row exists in another table.
DS.ResultsRow newRow;
newRow = getResultsRow((Guid) ds.tmpResultsAddEdit.Rows[ 0][ds.tmpR esultsAddE dit.Result sGUIDColum n.ColumnNa me]);
ds.Results.Rows.Add(newRow );
updateResults(ds);
this function works, but I can't add the row returned inot my other ds
private DS.ResultsRow getResultsRow(Guid ResultsGuid)
{
StarentDS ds = new StarentDS();
Starent.Data.StarentDSTabl eAdapters. ResultsTab leAdapter da = new Starent.Data.StarentDSTabl eAdapters. ResultsTab leAdapter( );
da.FillByResultsGUID(ds.Re sults,Resu ltsGuid);
StarentDS.ResultsRow row;
if (ds.Results.Rows.Count > 0)
{
row = (StarentDS.ResultsRow)ds.R esults.Row s[0];
return row;
}
else
{
row = ds.Results.NewResultsRow() ;
row.ResultsGUID = ResultsGuid;
return row;
}
}
What I want to do with my function:
Check to see if a row exists in a database using a guid.
If it does, return that row.
If it doesn't, return a new row.
The problem is that after I return this row, I try to add it to my new dataset and update it. When I do, it says the row exists in another table.
DS.ResultsRow newRow;
newRow = getResultsRow((Guid) ds.tmpResultsAddEdit.Rows[
ds.Results.Rows.Add(newRow
updateResults(ds);
this function works, but I can't add the row returned inot my other ds
private DS.ResultsRow getResultsRow(Guid ResultsGuid)
{
StarentDS ds = new StarentDS();
Starent.Data.StarentDSTabl
da.FillByResultsGUID(ds.Re
StarentDS.ResultsRow row;
if (ds.Results.Rows.Count > 0)
{
row = (StarentDS.ResultsRow)ds.R
return row;
}
else
{
row = ds.Results.NewResultsRow()
row.ResultsGUID = ResultsGuid;
return row;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.