vb.net - How update a SQL table from a modified datatable? -
i used dataset designer create ftwdataset holds alarmtext table sqlexpress database. far form contains datagridview1. code below shows contents of alarmtext table plus 1 added checkbox column (which populate display-only data, , not issue here).
dim ta new ftwdatasettableadapters.alarmtexttableadapter dim dt new ftwdataset.alarmtextdatatable ta.fill(dt) datagridview1.datasource = dt 'create new bool column in datatable dt.columns.add("newcol", (new boolean).gettype) what else need use datagridview edit , save values in alarmtext table?
here's brief msdn walkthrough on topic.
some notes:
- you shouldn't need binding source persist changes database.
- to make table adapter accessible other procedures in form, make form-scoped (a.k.a. member) variable instead of method-scoped, in example.
- if created
datasetusing dataset designer, , you're fetching original data more simple table or view, adapter won't know how update in original database. have manually configureupdatecommand in situation. reference, see tableadapter update commands section in above link.
i should mention avoid tableadapters in ado.net plague. in theory they're convenient , powerful. in practice, many of them (especially 1 oracle provider) buggy, , if don't work right you're totally screwed.
if you're pulling 1 underlying table, adapter should work fine (so ignore nihilistic advice time being). may adding additional column in code breaks adapter (since there's no corresponding column in database table).
Comments
Post a Comment