我刚开始研究asp.net。我有一些代码可以在VB中使用,但不能在asp中使用。
我已经把这个放在页面上了_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中,只要显示表单,标签就会显示"已连接"。
必须是:
受保护的子页面加载(ByVal sender As Object,ByVal e As System.EventArgs(处理我的加载