vb.net - Dataadapter for each datagridview wont work -
i have 3 datagridviews
datagridview1, datagridview2, datagridview3
each datagridview being bind using different data adapters , different bindings
datapter1, dataadapter2, dataadapter3, binding1 binding2 , binding3
'binding dgv1 datapter1.selectcommand = mycmd datapter1.fill(dset, "something") binding1.datasource = dset.tables("something1") datagridview1.datasource = binding1 'binding dgv2 datapter2.selectcommand = mycmd datapter2.fill(dset, "something") binding2.datasource = dset.tables("something2") datagridview2.datasource = binding2 'binding dgv3 datapter3.selectcommand = mycmd datapter3.fill(dset, "something") binding3.datasource = dset.tables("something3") datagridview3.datasource = binding3
when time wanted update datagridview1
dim firstbuilder new mysqlcommandbuilder(me.dataadapter1) me.dataadapter1.update(me.binding1.datasource) me.binding1.resetbindings(false)
it prompts me error that
missing datacolumn 'located in datagridview3' in datatable 'of datagridview3' source column 'located in datagridview3'
i don't see why have error since used different bindings , different dataadapters each datagridview. need fix issue...
i have struggled same issue days years ago... created custom class in end. created separate dataadapters , -commandbuillder each datatable. not sure if efficient way, works:
'1 dataset full db public dbdataset new dataset {.casesensitive = false} '1 datatable, dataadapter en commandbuilder per table private listof_datatables new list(of datatable) private listof_dataadapters new list(of oledbdataadapter) private listof_command new list(of oledbcommand) private listof_commandbuilder new list(of oledbcommandbuilder) public sub load_table(tablename string) 'load accesstable dataset dim sqlstring string = "select * " & tablename.toupper dim dbcon new oledbconnection(_dbconnstring_full) dbcon.open() listof_dataadapters.add(new oledbdataadapter) listof_command.add(new oledbcommand(sqlstring, dbcon)) listof_dataadapters(listof_dataadapters.count - 1).selectcommand = listof_command(listof_command.count - 1) listof_commandbuilder.add(new oledbcommandbuilder(listof_dataadapters(listof_dataadapters.count - 1))) listof_commandbuilder(listof_commandbuilder.count - 1).quoteprefix = "[" listof_commandbuilder(listof_commandbuilder.count - 1).quotesuffix = "]" listof_dataadapters(listof_dataadapters.count - 1).fill(dbdataset, tablename) listof_datatables.add(dbdataset.tables(tablename)) 'get primary keys dim ucollist new list(of string) dim myschema datatable = ctype(dbcon, oledbconnection).getoledbschematable(oledbschemaguid.primary_keys, new object() {nothing, nothing, tablename}) dim columnordinalforname integer = myschema.columns("column_name").ordinal each r datarow in myschema.rows ucollist.add(r.itemarray(columnordinalforname).tostring) next 'set primary keys dim keycolumn(ucollist.count) datacolumn index = 0 ucollist.count - 1 keycolumn(index) = dbdataset.tables(tablename).columns(ucollist(index)) next dbdataset.tables(tablename).primarykey = keycolumn dbcon.close() end sub public sub update_tables() dim nradap integer = listof_dataadapters.count adapterindex = 0 nradap - 1 listof_dataadapters(adapterindex).update(dbdataset.tables(adapterindex)) next end sub
Comments
Post a Comment