我刚开始看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中,只要显示表单,标签就会显示“已连接”。
答案 0 :(得分:1)