问题
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".
回答1:
it must be:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
来源:https://stackoverflow.com/questions/6552908/my-labels-text-isnt-changing-on-page-load-asp-net