dataset won't save back to database  
Author Message
ciarank





PostPosted: Visual Basic General, dataset won't save back to database Top

hi all

i have created an SQL db containing 1 table within VB 2005 express.
i then created a datasource to connect to the DB.
A dataset was then created.
i dragged the dataset onto my "Form1.vb" and bindingsource, tableadapter and binding navigator were then created.

i then pressed f5 to run.

I can nvavigate through the records and create new one's but when i click on the save icon and then exit, the new records are not written back to the DB.

any ideas



Visual Basic17  
 
 
DMan1





PostPosted: Visual Basic General, dataset won't save back to database Top

has an update command been assigned to the dataset



 
 
ciarank





PostPosted: Visual Basic General, dataset won't save back to database Top

yep. this is the code, which is all auto created when you drag the dataset onto the form:
 
 Private Sub TblCustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Me.Validate()
        Me.TblCustomerBindingSource.EndEdit()
        Me.TblCustomerTableAdapter.Update(Me.CustomerDataSet.tblCustomer)

    End Sub

strange thing is that all this worked on Beta2 version. just since i installed latest version that i'm getting this issue...


 
 
ciarank





PostPosted: Visual Basic General, dataset won't save back to database Top

yep. this is the code i use. which is all auto created when i drag the dataset onto the form

  Private Sub TblCustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.TblCustomerBindingSource.EndEdit()
        Me.TblCustomerTableAdapter.Update(Me.CustomerDataSet.tblCustomer)

    End Sub

strange thing is, all this worked before in beta2 version. since i upgraded this has ceased working..


 
 
KrisLa_MS





PostPosted: Visual Basic General, dataset won't save back to database Top

Thanks for the question ciarank.  I have a couple of possible solutions to the problem:

1) If the code you pasted in is exactly as it appears in the project then the method you are calling to do the save seems to be missing a Handles clause for the button in the BindingNavigator.  If this isn't the source of the problem then:

2) This may be you experiencing one of the idiosyncrises of LocalData whereby we copy the .mdf file into your bin directory on every F5 operation.  This essentially eliminates the data that was added to the DB in previous F5 sessions.  This is a change from Beta 2 where we would only copy the file if it had changed in the designer.  Unfortunately only copying sometimes had a potential to cause corruption of the .ldf file associated with the database file.  For more information on this please see our blog at:  https://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx
< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Hope this helps,

      Kris


 
 
ciarank





PostPosted: Visual Basic General, dataset won't save back to database Top

hi kris

just to clarify, the code i pasted is exactly the code from my project. so, looks like it is missing a Handles Clause. As all this code is created by a wizard i am wondering how to fix it.

i mean, what should the code read instead

btw, i have looked at point 2 you gave and the relevant blog but don't think it offers the correct solution. although i cpuld be wrong i guess..Smile

thx




 
 
ciarank





PostPosted: Visual Basic General, dataset won't save back to database Top

sorry Kris!

i made a mistake! there is a handles clause write at the end of the first line of code...


 
 
ciarank





PostPosted: Visual Basic General, dataset won't save back to database Top

i have also created an ACCESS db on a mapped network drive and get the same results.

this problem is happenning on both my home computer and work computer.

getting annoyed now!


 
 
pteal





PostPosted: Visual Basic General, dataset won't save back to database Top

I'm having the exact same problems, as ciarank. Not sure why as i've downloaded some of sample lessons from learnvisualbasic.net which deal with databases and they work fine. But when i come to create my own database app it won't update. even though all the properties and code are exactly the same as the samples i've downloaded.


 
 
pteal





PostPosted: Visual Basic General, dataset won't save back to database Top

Ok i've sorted it, if you click the database's .mdf file in the solution explorer then go to the properties windows and change 'copy to output directory' to 'copy if newer' and its all working!!!!
 
 
ciarank





PostPosted: Visual Basic General, dataset won't save back to database Top

excellent!

thx pteal - that worked! i was tearing my hair trying to get this to work.

i think Kris's post (and link to blog) also pointed to this being the issue but i guess i didn't fully understand what it was saying...


anyway, all sorted now. Big Smile


 
 
hiwiller





PostPosted: Visual Basic General, dataset won't save back to database Top

Ok i've sorted it, if you click the database's .mdf file in the solution explorer then go to the properties windows and change 'copy to output directory' to 'copy if newer' and its all working!!!!


WOW, thanks for posting this.

I'm an experienced programmer and dba in non-ms products and am trying to learn VB and I never would have figured this out. I poked around in the autogenerated code for hours trying. Phew, I can now continue my lessons. :)

 
 
edmond koni





PostPosted: Visual Basic General, dataset won't save back to database Top

Hi

I already made this experience. Problem is that datasets are copies of database files so when You press f5 to run app it does not save to the original database the records. But if You build the program and run it fm the exe it normally works to mdb or mdf data files.

Do not forget to install first the latest dotnet. The early one which came with the VB 2005 setup will not save any data to database even in exe mode