我的标签文本在page_load asp.net上没有变化

时间:2011-07-01 20:28:18

标签: asp.net vb.net sqlclient

我刚开始看asp.net。我有这个代码在VB中工作,但不是在asp。

我把它放在page_load中:

Dim db_con As SqlConnection, ssql As String, db_cmd As SqlCommand, rdr As SqlDataReader
    db_con = New SqlConnection("Data Source=myServer;Initial Catalog=processes;User Id=usrID;Password=mypwd;")
    db_cmd = New SqlCommand()
    ssql = "SELECT * FROM command_table_links WHERE command_id = 1"
    db_con.Open()
    db_cmd.Connection = db_con
    db_cmd.CommandText = ssql
    db_cmd.CommandType = Data.CommandType.Text

    rdr = db_cmd.ExecuteReader()
    rdr.Read()
    If rdr.HasRows Then
        lblTest.Text = "It connected"
    Else
        lblTest.Text = "No Connection"
    End If

    rdr.Close()
    db_con.Close()

知道为什么这在asp.net中不起作用?问题是标签是空白的。在vb.net中,只要显示表单,标签就会显示“已连接”。

1 个答案:

答案 0 :(得分:1)

必须是:
    受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load