vb.net - Record duplication on dataset update -


have strange behaviour , have no idea going on after investigation. have datagridview on form. set datasource of datagrid getdataset method. user cannot add new rows manually or either code. there no way add new row. there 2 columns last represent integer - position user can change. somehow when trying update records (not always) update of sqldataadapter trying put duplicate entry table. before save button option checking checkchangesdataset before allow makechangesdataset.

question: wrong below code use check whether dataset has been changed , update rows? if not cmdbuilder variable if not used anywhere?

 private readonly getsectiondataset new dataset   public function getdataset() dataset implements idbmanipulation.getdataset             using con new sqlconnection(strcon)                 using cmd new sqlcommand("select id, name, position tbarticels position<>1", con)                     con.open()                     ' create data adapter in method , throw away afterwards                     using getprojectsdataadapter = new sqldataadapter(cmd)                         getprojectsdataadapter.fill(getsectiondataset, "main")                     end using                 end using             end using             return getsectiondataset         end function           public function checkchangesdataset() boolean implements idbmanipulation.checkchangesdataset             dim result boolean = false             if getsectiondataset.haschanges                 result = true             end if             return result         end function          public sub makechangesdataset() implements idbmanipulation.makechangesdataset             if getsectiondataset.haschanges                 dim integer                 using con new sqlconnection(strcon)                     con.open()                     using transaction = con.begintransaction                         try                             using cmd new sqlcommand("select id, name, position tbarticels position<>1", transaction.connection)                                 ' create data adapter in method , throw away afterwards                                 cmd.connection = con                                 cmd.transaction = transaction                                  using getprojectsdataadapter = new sqldataadapter(cmd)                                     dim cmdbuilder new sqlcommandbuilder(getprojectsdataadapter)                                     getprojectsdataadapter.update(getsectiondataset, "main")                                 end using                             end using                              transaction.commit()                          catch ex exception                             transaction.rollback()                             throw 'rethrow exception.                         end try                     end using                 end using             end if         end sub 

meantime secured field ("name") in table avoid duplicates insertion using unique key on field because seems field going duplicated somehow dataadapter, , immediatly error message on random duplication occur on save:

enter image description here


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -