1 Replies - 378 Views - Last Post: 24 September 2013 - 06:43 AM Rate Topic: -----

#1 south73paw  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 88
  • Joined: 06-October 08

Problem Saving Data to Database (Single Table)

Posted 24 September 2013 - 03:12 AM

Hi

(Apologies. I've posted this in the VB .Net section, before I saw a Databases area. Not quite sure where the best place for this is...)

I'm having trouble saving data to a database file. Specifically, saving edits made to records in a data table, via a dataset, using the Update method of a tableadaptermanager. I checked this in multiple sources, but it still doesn't work properly.

I'm using VB .Net 2010 Professional, Windows 7, 64-bit.

My code is below. This version is based on MSDN documentation, Saving Data to a Database (Single Table)

01
Public Class frmMain
02

03
Private Sub PhoneTableBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhoneTableBindingNavigatorSaveItem.Click
04

05
Me.Validate()
06
Me.PhoneTableBindingSource.EndEdit()
07
Me.TableAdapterManager.UpdateAll(Me.PhoneDataSet)
08

09
End Sub
10

11
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
12

13
'TODO: This line of code loads data into the 'PhoneDataSet.PhoneTable' table. You can move, or remove it, as needed.
14
Me.PhoneTableTableAdapter.Fill(Me.PhoneDataSet.PhoneTable)
15

16
End Sub
17

18
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
19

20
Try
21

22
Me.Validate()
23
Me.PhoneTableBindingSource.EndEdit()
24
Me.PhoneTableTableAdapter.Update(Me.PhoneDataSet.PhoneTable)
25
MsgBox("Update successful")
26

27
Catch ex As Exception
28

29
MsgBox("Update failed")
30

31
End Try
32

33
End Sub
34

35
End Class


I followed the MSDN page referenced above:
used the data configuration wizard
dragged controls from the data sources window to the form
updated the btnSave_Click code to reflect the data objects (e.g. PhoneTable)


Data is being saved to the dataset, but not the actual database file sitting on my hard drive (in the project folder).

I've tried running the program, making an edit to an existing record, click the save button then...
using the next and previous buttons on the binding navigator to progress through records
when I return to the record I edited, the change I saved through btnSave_Click is still there
when I stop debugging and press F5 again, the edited data still appears


BUT...when I press Ctrl+S to save the VB project, then start debugging again, the edited data is no longer there; only the original.

I've checked the Access file and only the original data is there. None of my edits are being saved at all.

Can anyone tell me why this isn't working? The advice on the MSDN page makes sense (and corroborates a number of other resources I used so far), but the Update method of the table adapter seems to be ignored.

Thanks in advance! :dontgetit:/>/>

Is This A Good Question/Topic? 0
  • +

Replies To: Problem Saving Data to Database (Single Table)

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9497
  • View blog
  • Posts: 35,844
  • Joined: 12-June 08

Re: Problem Saving Data to Database (Single Table)

Posted 24 September 2013 - 06:43 AM

Please do not double post. It appears to be an issue with VB.NET and not the database. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1