我的标签文本在 page_load asp.net 上没有更改

发布于 2024-11-18 06:29:14 字数 805 浏览 4 评论 0原文

我刚刚开始研究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 中,一旦显示表单,标签就会显示“已连接”。

I'm just starting out looking at asp.net. I've got this code that works in VB, but not in asp.

I've put this in the 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()

Any idea why this wouldn't work in asp.net? The issue is that the label is blank. In vb.net as soon as the form is shown, the lable says "It connected".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2024-11-25 06:29:14

它必须是:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 处理 Me.Load

it must be:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文