Question Can't save Dataset changes to actual database

AngeloC

New member
Joined
Jul 17, 2014
Messages
3
Programming Experience
Beginner
Hello, I am very new in vb.net programming (first time ever), I tried many online courses and tested a lot before trying my own stuff. I am running in a problem that I can't figure out. I make changes in a dataset and I can view the changes but when I try to update the actual database nothing changes.

I have to work with a very bad designed database (not mine) but everything works except for the update.

Can anyone help?

I don't know if I should put the code in here or send it to the person that would want to help

Thank you
 
Hi and welcome to the forum,

Yes, please do post the code that you have tried so that we can try and help you to define what the issue is and guide you to where you are going wrong.

Cheers,

Ian
 
If you do post code, please just post the relevant code. If the issue is saving data to the database, just the code that does the saving for a start and then, if we need more, we'll ask for it.

That said, there are things that you can do first. It's simply not possible that nothing happens when you save data. Either the save succeeds or an exception is thrown. If the save succeeds then either changes were saved or there were no changes to save in the first place. Are you using ADO.NET? Are you using a data adapter or table adapter to save changes from a DataTable? That's not the only option but it's the most common for beginners. In that case, you'll be calling Update to save changes. Update returns the number of rows affected by the operation. If a number is returned then no exception is being thrown so the save is succeeding. If that number is not zero then data is being saved. Check that first.
 
Thank you for responding. Before I post any code, I will review it again taking in consideration what you wrote.

1) Yes I am using ADO.NET
2) I am using a DataAdapter (OleDbDataAdapter)

Update returns 0 every time.

Like I said, I will review my code again and then post the relevant code if it still doesn't work

Thank you so much for replying.
 
If Update is returning zero then there are no changes to save in the DataTable. The first thing to consider in that case is whether you're calling AcceptChanges before Update. You should not be so, if you are, that's the issue.
 
Very interesting, I did have AcceptChanges after I change values in the Dataset and before calling Update. I removed AcceptChanges and now I have an exception trown by the Update command. It's not what we want but at least now the update is actually doing something. The exception that gets trown is "Query too complex".
The Query is built by GetUpdateCommand and I know the database has A LOT of fields and yes the Query is very complex because it includes all the fields.
What is the workaround for that?

Thank you so much for your help
 
Back
Top