• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

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;
            }
        }


0
jackjohnson44
Asked:
jackjohnson44
1 Solution
 
Bob LearnedCommented:
You need to use DataTable.ImportRow from the target table to add a row.

Bob
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now