LMS知識社群ePortfolio各系上網率圖資處首頁登入
2315
by 博盧明濠 2018-04-11 10:04:48, 回應(0), 人氣(31)
Imports System.Data
Imports System.Data.SqlClient
Partial Class student
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim objCon As SqlConnection
        Dim objCmd As SqlCommand
        Dim objDR As SqlDataReader
        Dim strDbCon, strSQL As String
        strDbCon = "Data Source=(LocalDB)\v11.0;" &
            "AttachDbFilename=" &
            Server.MapPath("App_Data\ch7_hwDB.mdf") &
            ";Integrated Security=True"
        objCon = New SqlConnection(strDbCon)
        objCon.Open()
        strSQL = "SELECT * FROM 客戶資料表"
        objCmd = New SqlCommand(strSQL, objCon)
        objDR = objCmd.ExecuteReader()
        If objDR.HasRows Then
            Label1.Text = "客戶資料表: <hr/>"

            Do While objDR.Read()
                Label1.Text &= objDR("客戶代號") & " - "
                Label1.Text &= objDR("客戶姓名") & " - "
                Label1.Text &= objDR("電話") & " - "
                Label1.Text &= objDR("城市") & " - "

                Label1.Text &= objDR("區域") & "<br/>"
            Loop
        Else
            Label1.Text = "資料表中沒有記錄資料!"
        End If
        objDR.Close()
        objCon.Close()
    End Sub

End Class