ASP页面显示一条查询的记录的值
Hi 大虾们,麻烦告诉我应该咋做。
在我的页面里面有三个label, 分别为lblName,lblDID,lblExt我的后台在页面加载的时候的VB代码如下:
Dim cn As SqlConnection = New SqlConnection()
cn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("SoftPhoneServices").ConnectionString
If cn.State <> ConnectionState.Open Then
cn.Open()
End If
Dim cm As SqlCommand = New SqlCommand()
cm.CommandText = "SELECT Name, Extension FROM PVGL_PhoneList WHERE SAPID=@UserID"
cm.Connection = cn
Dim rd As SqlDataReader
cm.Parameters.Add("@UserID", SqlDbType.Char, 10).Value = 'i00001'
rd = cm.ExecuteReader()
If Not rd.HasRows Then
rd.Close()
rd = Nothing
cm.Dispose()
cm = Nothing
cn.Close()
cn = Nothing
lblExt.Text = "Unknow Ext."
lblDID.Text = "Unknow DID"
lblName.Text = "Unknow User"
Else
rd.Close()
rd = Nothing
cm.Dispose()
cm = Nothing
cn.Close()
cn = Nothing
End If
每个查询肯定是只有唯一的一条记录,我不知道如何将我查询出来那一行的Name, Extension 值赋给两个lable。高手指点一下吧。急用!
------解决方案--------------------
If rd.Read() Then
lblExt.Text = rd("Name").ToString()
lblDID.Text = rd("Extension ").ToString()
rd.Close()
rd = Nothing
cm.Dispose()
cm = Nothing
cn.Close()
cn = Nothing
Else
rd.Close()
rd = Nothing
cm.Dispose()
cm = Nothing
cn.Close()
cn = Nothing
End If
------解决方案--------------------
lblExt.Text = "Unknow Ext."
改成:
lblExt.Text = rd("Name").ToString()