c# add datarow to another table

Posted on 2007-08-03
Last Modified: 2013-11-05
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]);

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();
            StarentDS.ResultsRow row;

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

Question by:jackjohnson44
    1 Comment
    LVL 96

    Accepted Solution

    You need to use DataTable.ImportRow from the target table to add a row.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now