CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Getting IDs for newinserted rows

    Hello!

    I insert some new rows into a DataTable and then insert the rows into the database via

    Code:
    changes = dataTable.GetChanges();
    if (changes != null)
    {         int nRowsUpdated = dataAdapter.Update(changes);
    }
    This works fine. But now I need to know to values of the "auto_incremet primary key" the database gave to this new rows. So how can I get the ids of the records I just inserted?

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: Getting IDs for newinserted rows

    Busy

  3. #3
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Getting IDs for newinserted rows


  4. #4
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Getting IDs for newinserted rows

    Quote Originally Posted by martho
    Hello!

    I insert some new rows into a DataTable and then insert the rows into the database via

    Code:
    changes = dataTable.GetChanges();
    if (changes != null)
    {         int nRowsUpdated = dataAdapter.Update(changes);
    }
    This works fine. But now I need to know to values of the "auto_incremet primary key" the database gave to this new rows. So how can I get the ids of the records I just inserted?
    call this instead:
    int nRowsUpdated = dataAdapter.Update(datatable);

    and note how your id fields are all now popualted. magic
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured