Imports System.Data.OleDb Partial Class _Default Inherits System.Web.UI.Page Dim straccess As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\ihpnguyen\practice.mdb;Persist Security Info=True" Dim cnn As OleDbConnection Dim cmd As OleDbCommand Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' open connection Try cnn = New OleDbConnection(straccess) cnn.Open() Catch ex As Exception MsgBox(ex.ToString()) End Try ' process Dim sqlSelect As String = _ "select * from ware" cmd = New OleDbCommand(sqlSelect, cnn) Dim reader As OleDbDataReader reader = cmd.ExecuteReader() Dim str As String = "" str += "
" str += "" str += "STT | HSXuat | NSXuat | TSP | NGNHAP | " str += "
" Try While reader.Read str += "" str += "" + reader.GetValue(0) str += " | " + reader.GetValue(1) str += " | " + reader.GetValue(2) str += " | " + reader.GetValue(3) str += " | " + reader.GetValue(4) str += " | " str += "
" End While Catch ex As Exception Finally Try reader.Close() Catch ex As Exception End Try End Try Dim indexnew As Integer = indexlast(cnn) savewarte(cnn,indexnew,'DELL') ' close connection Try cnn.Close() Catch ex As Exception
MsgBox(ex.ToString()) End Try str += "
" lbresult.Text = str End Sub Public Sub loadGrid(ByVal cmd As OleDbCommand) Dim da As New OleDbDataAdapter(cmd) Dim ds As New System.Data.DataSet() da.Fill(ds) gvlist.DataSource = ds gvlist.DataBind() End Sub Public Function indexlast(ByVal cnn As OleDbConnection) As Integer Dim sqlInsert = "SELECT ID FROM ware ORDER BY ID DESC" Dim cmd As New OleDbCommand(sqlInsert, cnn) Dim index As Integer = cmd.ExecuteScalar() Return index + 1 End Function Public Sub savewarte(ByVal cnn As OleDbConnection, ByVal index As Integer, ByVal company As String) Dim sqlInsert = "INSERT INTO ware VALUES(1,'Dell','USA','DELL D234','2009-02-15')" Dim cmd As New OleDbCommand(sqlInsert, cnn) cmd.ExecuteNonQuery() End Sub End Class