vb.net - how to use recordset movelast -


i need code can use old rs.movelast vb.net 2010.. simple way query record automatic select last..

here connection sample call in form..///

public function executesqlquery(byval sqlquery string) datatable try dim sqlcon new oledbconnection(cnstring) dim sqlda new oledbdataadapter(sqlquery, sqlcon) dim sqlcb new oledbcommandbuilder(sqlda) sqldt.reset() ' refresh sqlda.fill(sqldt) catch ex exception msgbox("error : " & ex.message) end try return sqldt end function 

sqldt.rows(sqldt.rows.count-1) last record of datatable sqldt. sqldt.rows.count-1 return last index of rows in filled table. hope you. thanks

imports system.data.oledb public class form1 public cnstring string = "provider=sqloledb;data source=hp-pc\sqlexpress;persist security info=true;password=sa;user id=sa;initial catalog=accounts" private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click dim ssql string = "select * tbl_access" dim dt datatable dt = executesqlquery(ssql) textbox1.text = dt.rows(dt.rows.count - 1)(0) 'value of first column of last row of datatable dt textbox2.text = dt.rows(dt.rows.count - 1)(1) 'value of second column of last row of datatable dt end sub public function executesqlquery(byval sqlquery string) datatable try dim sqlcon new oledbconnection(cnstring) dim sqlda new oledbdataadapter(sqlquery, sqlcon) dim sqlcb new oledbcommandbuilder(sqlda) dim sqldt new datatable sqldt.reset() ' refresh sqlda.fill(sqldt) return sqldt catch ex exception msgbox("error : " & ex.message) return nothing end try end function end class 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -