Saving dataset changes with TableAdapter.Update(DataTable)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Saving dataset changes with TableAdapter.Update(DataTable)

  1. #1
    Join Date
    Nov 2010
    Posts
    45

    Saving dataset changes with TableAdapter.Update(DataTable)

    I have a dataset that fills a tableadapter and I'd like to be able to post changes made to the dataset to a database with a date marking the changes. I've never used the TableAdapter.Update method before and was wondering if someone has any good tutorial links for that method.

    Here is the code:

    Code:
    Imports System.Data.SqlClient
    Imports System.Data
    Public Class ExceptionEdit
        Private Sub ExceptionEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'MDRDataSet.scratchpad3' table. You can move, or remove it, as needed.
            Me.Scratchpad3TableAdapter.Fill(Me.MDRDataSet.scratchpad3)
            Exceptioncopy()
        End Sub
        Private Sub SaveExceptionButton(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveexceptionsButton.Click
            Try
                Me.Validate()
                Me.Scratchpad3BindingSource.EndEdit()
                Me.Scratchpad3TableAdapter.Update(Me.MDRDataSet.scratchpad3)
                MsgBox("Update successful")
    
            Catch ex As Exception
                MsgBox("Update failed")
            End Try
        End Sub
    is it possible to update another database and not the scratchpad3 (since that's a temporary table and the actual table I need to update is a table called "Exceptions")

    thank you

    Doug
    Last edited by dougancil; May 24th, 2011 at 03:39 PM. Reason: didn't have code

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

  3. #3
    Join Date
    Nov 2010
    Posts
    45

    Re: Saving dataset changes with TableAdapter.Update(DataTable)

    Hannes,
    I looked at those and when I tried the code in what I've built so far, I get the error:

    InvalidOperationException occured:
    Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

    I've looked that error up and have seen a variety of answers. What I'm needing to do is to save the data back to another database and not the one that's filling the tableadapter. Is that possible?

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Saving dataset changes with TableAdapter.Update(DataTable)

    another ( totally different ) database, or another tabel ( within the same database ) ?

  5. #5
    Join Date
    Nov 2010
    Posts
    45

    Re: Saving dataset changes with TableAdapter.Update(DataTable)

    Same database just another table. The table that is filling the table adapter is a temporary table ... and I want to update a table called Exceptions and not scratchpad3.

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Saving dataset changes with TableAdapter.Update(DataTable)

    If you bind it to the actual table, it'd be easy to update. Use TEXT BOXES for the temporary record that the user sees. You can even fill it automatically for them.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Nov 2010
    Posts
    45

    Re: Saving dataset changes with TableAdapter.Update(DataTable)

    The table that I'm updating is "raw" data but the table that's filling in the table adapter is filtered with a stored procedure. So hence why I can't bind the table that I'm updating to the form.

  8. #8
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Saving dataset changes with TableAdapter.Update(DataTable)

    Either use a SP to update the table.

    If they don't go for that, don't use the SP's. This is .Net, not VB6
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center