Imports System.Data.OleDb
Public Class index
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents btnInsert As System.Web.UI.WebControls.Button
Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Public strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " &
Server.MapPath("db1.mdb")
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
LoadData()
End Sub
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnInsert.Click
Dim cmd As New OleDbCommand("INSERT INTO Customers (FirstName, LastName)VALUES('" &
txtFirstName.Text & "','" & txtLastName.Text & "')", New
OleDbConnection(strConn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
LoadData()
End Sub
Sub LoadData()
Dim strSQL As String = "Select * From Customers"
Dim cmd As New OleDbCommand(strSQL, New OleDbConnection(strConn))
cmd.Connection.Open()
Repeater1.DataSource = cmd.ExecuteReader
Repeater1.DataBind()
cmd.Connection.Close()
cmd.Connection.Dispose()
End Sub
End Class
|