-
May 24th, 2011, 03:32 PM
#1
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
-
May 25th, 2011, 09:19 AM
#2
Re: Saving dataset changes with TableAdapter.Update(DataTable)
-
May 25th, 2011, 10:05 AM
#3
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?
-
May 25th, 2011, 10:09 AM
#4
Re: Saving dataset changes with TableAdapter.Update(DataTable)
another ( totally different ) database, or another tabel ( within the same database ) ?
-
May 25th, 2011, 12:59 PM
#5
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.
-
May 25th, 2011, 02:14 PM
#6
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.
-
May 25th, 2011, 02:57 PM
#7
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.
-
May 25th, 2011, 11:41 PM
#8
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|