Anda di halaman 1dari 2

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 += "<table border=1>"
str += "<tr>"
str +=
"<th>STT</th><th>HSXuat</th><th>NSXuat</th><th>TSP</th><th>NGNHAP</th>"
str += "</tr>"
Try
While reader.Read
str += "<tr>"
str += "<td>" + reader.GetValue(0)
str += "</td><td>" + reader.GetValue(1)
str += "</td><td>" + reader.GetValue(2)
str += "</td><td>" + reader.GetValue(3)
str += "</td><td>" + reader.GetValue(4)
str += "</td>"
str += "</tr>"

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 += "</table>"
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

Anda mungkin juga menyukai