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