LMS知識社群ePortfolio各系上網率圖資處首頁登入
位置: 許睿升 > 未分類
鐸-20180314
by 許睿升 2018-03-14 11:42:54, 回應(0), 人氣(110)
Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    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, lblOutput As String
        strDbCon = "Data Source=(LocalDB)\v11.0;" &
            "AttachDbFilename=" &
            Server.MapPath("APP_data\School.mdf") &
            ";Integrated Security=True"
        objcon = New SqlConnection(strDbCon)
        objcon.Open()
        strSQL = "SELECT * FROM Students"
        objcmd = New SqlCommand(strSQL, objcon)
        objDR = objcmd.ExecuteReader()
        If objDR.HasRows Then
            Label1.Text = "資料表紀錄:<hr/>"
            Do While objDR.Read()
                Label1.Text &= objDR("sid") & "-"
                Label1.Text &= objDR("name") & "-"
                Label1.Text &= objDR("tel") & "<br/>"
            Loop
        Else
            Label1.Text = "資料表中沒有紀錄!"
        End If
        objDR.Close()
        objcon.Close()
    End Sub
End Class

附件: