Last post Dec 05, 2011 08:02 PM by Decker Dong - MSFT
Dec 01, 2011 03:50 PM|frost|LINK
Hi, I have an SQL table of data that I'm outputting to an xmldatasource and binding that xmldatasource to a menu control. The sql string that I'm using checks to see if a user id exists in the db table, and if it doesn't, there are no records returned.
However, when I do that, my code fails. I was just going to check to see what rows are returned in a dataset to make the menu control visible or not if there were no records, but it's failing.
How can I check the records returned and if there is nothing populated through the sql string, then I just want the control to be not visible.
Below is my code.
Private Sub populateMenuItems()
Dim cnMap As SqlConnection = myDataCN
Dim strSQL As String
strSQL = "SELECT Display_Name, Extents FROM [User_Access] WHERE (UserID = '10') ORDER BY Display_Name FOR XML AUTO, ROOT('myMenu')"
Dim sqlCommand As SqlCommand = New SqlCommand(strSQL, cnMap)
Dim sb As New StringBuilder()
Dim rdr As SqlDataReader = sqlCommand.ExecuteReader()
Dim da As New SqlDataAdapter(strSQL, cnMap)
Dim ds As New DataSet
If ds.Tables("mytable").Rows.Count > 0 Then
ASPxMenu4.Visible = False
XmlDataSource2.EnableCaching = False
XmlDataSource2.Data = sb.ToString()
ASPxMenu4.DataSource = XmlDataSource2
ASPxMenu4.TextField = "Display_Name"
ASPxMenu4.NavigateUrlField = "Extents"
Dim item As MenuItem = ASPxMenu4.Items.FindByText("myMenu")
item.Text = "Menu"
Dec 02, 2011 09:41 PM|Decker Dong - MSFT|LINK
Sorry but there's something I cannot recognize……Please reformat your codes。
Dec 05, 2011 01:21 PM|frost|LINK
Those are single quotes. They just don't appear as such in this forums code block editor.
Dec 05, 2011 08:02 PM|Decker Dong - MSFT|LINK
In my mind，I think you can use XmlReader to do that——Sample like this below：
Dim objCmd As New SqlCommand("select * from employees for xml auto", objConn)
Dim xr As System.Xml.XmlReader = objCmd.ExecuteXmlReader()
' Here do what you want……