Imports System.Data Imports System.Data.OleDb Partial Class ReadUpdate Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then Session("序號") = "1" ReadData() End If End Sub Protected Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click Session("序號") = DropDownList1.Text Dim tk_provider = "Provider=Microsoft.ACE.OLEDB.12.0" Dim tk_database = "Data Source=" & Server.MapPath("Member.accdb") Dim tk_conn As New OleDbConnection(tk_provider & ";" & tk_database) Dim tk_sql As String tk_conn.Open() tk_sql = "Update 會員資料表 Set 帳號='" & TextBox1.Text & "',密碼='" & TextBox2.Text & "' Where 序號=" & Session("序號") Dim tk_cmd As New OleDbCommand(tk_sql, tk_conn) Label1.Text = "" tk_cmd.ExecuteNonQuery() If Err.Number = 0 Then Label1.Text = "更新成功!" Else Label1.Text = Err.Description End If tk_conn.Close() End Sub Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged Session("序號") = DropDownList1.Text ReadData() End Sub Sub ReadData() Dim tk_provider = "Provider=Microsoft.ACE.OLEDB.12.0" '資料庫所在的路徑 Dim tk_database = "Data Source=" & Server.MapPath("Member.accdb") Dim tk_conn As New OleDbConnection(tk_provider & ";" & tk_database) Dim tk_sql As String Dim tk_datareader As OleDbDataReader tk_sql = "SELECT 帳號,密碼 FROM 會員資料表 WHERE 序號 = " & Session("序號") tk_conn.Open() Dim tk_cmd As New OleDbCommand(tk_sql, tk_conn) tk_datareader = tk_cmd.ExecuteReader() Label1.Text = "" If tk_datareader.Read() = True Then TextBox1.Text = tk_datareader.Item(0).ToString() TextBox2.Text = tk_datareader.Item(1).ToString() End If tk_datareader.Close() tk_conn.Close() End Sub End Class