vb.net - Filling SQL Database Table from DataGridView -


once again turning help. little stuck when trying save data entered in datagridview sql table.

i have followed number of posts cant seam figure out

i declare following variables globally on form

dim sqladaptor new sqlclient.sqldataadapter dim con new sqlclient.sqlconnection dim builder sqlclient.sqlcommandbuilder 

i call when form loads

private sub setticketlist()       con.connectionstring = croptrackmod.strconn      sqladaptor.selectcommand = new sqlclient.sqlcommand("select stockref, weight, estimatedprice, estimatedprice, despatchedquantity, estimatedtransport, estimatedlinetotal ticketdetail", con)      builder = new sqlclient.sqlcommandbuilder(sqladaptor)      con.open()       dim mytable datatable = new datatable      sqladaptor.fill(mytable)       dgvticketdetail.datasource = mytable    end sub 

i call when user leaves row on data grid view should save sql table

private sub dgvticketdetail_rowleave     ' @ grid save'      dim mytable = ctype(dgvticketdetail.datasource, datatable)     sqladaptor.update(mytable) end sub 

when form loaded data grid view populated correct columns think first part ok. problem comes when saving data back. when run first time there no error message. when try second row following error:

update requires valid insertcommand when passed datarow collection new rows.

from can figure problem generated because there no update command set on data adaptor.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -