Imports System.Data Imports System.Data.OleDb Partial Class Shop03 Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Session("account") = "" Then Response.Redirect("Shop01.aspx") End If End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim tk_provider = "Provider=Microsoft.ACE.OLEDB.12.0" '資料庫所在的路徑 Dim tk_database = "Data Source=" & Server.MapPath("ShopDB.accdb") Dim tk_conn As New OleDbConnection(tk_provider & ";" & tk_database) Dim tk_sql As String Dim tk_datareader As OleDbDataReader tk_conn.Open() If DropDownList1.SelectedValue > 0 Then tk_sql = "Insert Into 訂購單(會員帳號,產品編號,數量) Values ('" & Session("account") & "','" & Session("PNO") & "'," & DropDownList1.SelectedValue & ")" Dim tk_cmd As New OleDbCommand(tk_sql, tk_conn) tk_cmd.ExecuteNonQuery() If Err.Number = 0 Then Label1.Text = "新增成功!" Else Label1.Text = Err.Description End If Else Label1.Text = "請選擇購買數量" End If tk_conn.Close() End Sub Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Response.Redirect("Shop01.aspx") End Sub Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Response.Redirect("Shop04.aspx") End Sub End Class