Question Table with wizard connection updates only if no other table is being updated

mrRogers

Well-known member
Joined
Jan 23, 2016
Messages
45
Programming Experience
3-5
I have a DGV with wizard created connection, ds, and da. I have another DGV that is filled and managed with code. I make changes to the first and it updates. I make changes to both and only the second one will update. in a btn click event :[If dsGM.HasChanges Then
daGM.Update(dsGM.tblGM)

End If

If ds.HasChanges Then
cmdBldr.GetUpdateCommand()
dA.Update(ds, tbl)

End If]
 
Firstly, that GetUpdateCommand call is pointless so get rid of it.

As for the question, you say that the issue is that the first DataSet's changes won't save and yet all you've shown us is code that saves changes from the second DataSet. If you want us to tell you why some code doesn't work, it would help to see that code.

When posting code, please post it as PLAIN TEXT, copied directly from the IDE if possible, between appropriate formatting tags, i.e.

[xcode=vb]your code here[/xcode]
 
If I could get some guidance before i waste your time on code that could be fundamentally wrong first. I understand a dataset holds a collection of tables. Should i load all the tables i need from a database in say the load event and then assign the DGV data source to the ds.table(?) i want to look at? the other clarification i need is that when i query, am i querring the already filled ds and filling the DGV or is th adapter going all the way back to the datatable and loading the ds with the queried info. thanks for being patient.
 
If I could get some guidance before i waste your time on code that could be fundamentally wrong first. I understand a dataset holds a collection of tables. Should i load all the tables i need from a database in say the load event and then assign the DGV data source to the ds.table(?) i want to look at? the other clarification i need is that when i query, am i querring the already filled ds and filling the DGV or is th adapter going all the way back to the datatable and loading the ds with the queried info. thanks for being patient.

None of that really has anything to do with your original question.

Anyway, a DataSet is basically a local representation of your database that stores cached data. It's empty to begin with. You call Fill on a data adapter or table adapter and data is retrieved from the database into the DataTables in the DataSet. You work with that local data cache. That is what gets bound to your controls and any changes you make are made to that local data. No changes are made to the database until you call Update on a data adapter or table adapter, at which point the changes are saved from the DataTables back to the database.

Note that a DataSet doesn't have to contain the same schema as your database or even any of the schema from your database. It often does because that's what's most convenient but it's certainly not always the case. Also, you can use a DataTable on its own if that's all you need. You would only use a DataSet if it offers some value.

If you use raw ADO.NET then you will use data adapters to populate DataTables, maybe in a DataSet and maybe not. If you used the Data Source wizard then that will generate a typed DataSet, which contains typed DataTables and also table adapters, which wrap data adapters. Typed DataSets have extra code that is specific to your data, so they make working with your data easier in many ways, e.g. you can access fields in rows using properties named after your columns, which means that you get the benefit of Intellisense and incremental compilation that you don't get when using Strings to identify columns.
 
Thanks, Reading this I think I discovered one fundamental thought process that I was doing wrong. I do not need a dataset for each table in a database. I rearranged to where I have one dataset that contains both tables with each having it's own data adapter. I still use row info from one to fill the second one via select statement. Now the updates for each using their own data adapters work.
 
Depending on the amount of data you have and how much is likely to be used in a session, it might be better to simply get all the data for both tables and let the data-binding filter what you see in the child control. If that sounds interesting, check this out:

Master/Detail (Parent/Child) Data-binding

The example works with an untyped DataSet but you can do the same with a typed DataSet. You simply have to manipulate the bindings in the designer.
 
Back
Top