Link to home
Start Free TrialLog in
Avatar of jackjohnson44
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.tmpResultsAddEdit.ResultsGUIDColumn.ColumnName]);
            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.StarentDSTableAdapters.ResultsTableAdapter da = new Starent.Data.StarentDSTableAdapters.ResultsTableAdapter();
            da.FillByResultsGUID(ds.Results,ResultsGuid);
            StarentDS.ResultsRow row;

            if (ds.Results.Rows.Count > 0)
            {
                row = (StarentDS.ResultsRow)ds.Results.Rows[0];
                return row;
            }
            else
            {
                row = ds.Results.NewResultsRow();
                row.ResultsGUID = ResultsGuid;
                return row;
            }
        }


ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial