sql server - Can't Figure Out how to show newly inserted rows to my Datagrid view -


i have sql table [dbo].[cashiers] ( cashier_id int primary key identity, cashier_name nvarchar(max) )

now loaded data in table datatable in vb.net

    private sub form1_load(sender object, e eventargs) handles mybase.load     using conn new sqlconnection(my.settings.lol)         try             dim adp new sqldataadapter              adp                 .selectcommand = new sqlcommand("select * [dbo].[cashiers]", conn)                 .fill(dt)             end             bs.datasource = dt             datagridview1.datasource = bs              adp.dispose()          catch ex exception             msgbox(ex.message, msgboxstyle.critical)                     conn.close()         end try     end using end sub 

i created 2 global variables

dim dt new datatable 'global variable dim bs new bindingsource 'global variable 

and have text box , button insert records

    private sub button1_click(sender object, e eventargs) handles button1.click     using conn new sqlconnection(my.settings.lol)         dim cmd new sqlcommand         cmd             .commandtext = "insert [dbo].[cashiers] ([casheir_name]) values (@cashier_name)"             .connection = conn             .parameters.add("@cashier_name", sqldbtype.varchar).value = textbox1.text.trim         end         try             conn.open()             cmd.executenonquery()              cmd.dispose()             textbox1.text = nothing             msgbox("added!")         catch ex exception             msgbox(ex.message, msgboxstyle.critical)                     conn.close()         end try     end using end sub 

all of working fine problem cant figure out how show newly inserted rows in datagridview , hoping if provide me code snippet or explain concept me , think that's working me right load whole new datatable new records , set new datasource datagrid view , sure not done way .

thanks in advance.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -