How to insert data into SQL Server database to a datagridview using vb.net -


i want retrieve data sql server 2012 database datagridview in vb. created connection class connecting each every form db. created method call getdata execute sql statement , fill data dataset. code data getdata button

private sub btngetdata_click(sender object, e eventargs) handles btngetdata.click     dim tmpds dataset      try          rowindex integer = 0 datagridview1.rows.count - 1              dim objcon new clscon             objcon.getdata("select * stockmf")              if objcon.ds.tables(0).rows.count > 0                 tmpds = objcon.ds                  datagridview1.rows(0).cells(0).value = tmpds.tables(0).rows(0).item("stockid")                 datagridview1.rows(0).cells(1).value = tmpds.tables(0).rows(0).item("itemno")                 datagridview1.rows(0).cells(2).value = tmpds.tables(0).rows(0).item("itemnm")                 datagridview1.rows(0).cells(3).value = tmpds.tables(0).rows(0).item("unitprice")                 datagridview1.rows(0).cells(4).value = tmpds.tables(0).rows(0).item("availqty")              end if            next rowindex      catch ex exception         msgbox(ex.message)     end try  end sub 

but 1 record database. how correct code retrieve records recorded in database? need know how clear datagridview

to fill datagridview, this

try    dim objcon new clscon    dim dt new datatable    dt = objcon.getdata("select * stockmf")    datagridview1.datasource = dt   catch ex exception    msgbox(ex.message) end try 

to remove data datagridview,

datagridview1.datasource = nothing 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -