I am having a really strange problem. I am creating a webpage that retrieves a list of links from a database and displays them. I retrieve the records and load them into an object list. However when I iterate through that list later I am getting duplicated items displayed.
The page to view the result is http://myhacc.azurewebsites.net/testlinks.aspx
There should be only 1 of each link and as you can see there are 2 of each. I havent the slightet as to why. I have been over my logic 10 times.
I am using a Microsoft SQL Server running on microsoft azure The Web Page is also hosted on microsoft azure as a web app.
I have checked my database and there are no duplicate entries in the database. the structure of the database is as follows
Table: myportal_lcat Field: id - integer Field: name - text
Table: myportal_lhref Field: catid - integer Field: dname - text Field: href - text
the code is as follows
<%@ Page Title="" Language="VB" MasterPageFile="~/Main.master" %>
<script runat="server">
Private oCon As Data.SqlClient.SqlConnection
Private oCon2 As Data.SqlClient.SqlConnection
Private oCatCom As New Data.SqlClient.SqlCommand
Private oCatRead As Data.SqlClient.SqlDataReader
Private oItemCom As New Data.SqlClient.SqlCommand
Private oItemRead As Data.SqlClient.SqlDataReader
Private liLinks As New List(Of linkItem)
Private Sub Page_Load() Handles Me.Load
oCon = New Data.SqlClient.SqlConnection("Server=xxxx,1433;Database=xxxxx;User ID=xxxxxx;Password=xxxxx;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;")
oCon2 = New Data.SqlClient.SqlConnection("Server=xxxxxx,1433;Database=xxxx;User ID=xxxx;Password=xxxxx;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;")
oCon.Open()
oCon2.Open()
oCatCom.Connection = oCon
oCatCom.CommandText = "Select * From myportal_lcat"
oItemCom.Connection = oCon2
oItemCom.CommandText = "Select * From myportal_lhref"
oCatRead = oCatCom.ExecuteReader()
oItemRead = oItemCom.ExecuteReader()
Do While oItemRead.Read
liLinks.Add(New linkItem With {.CatID = oItemRead("catid"), .DName = oItemRead("dname"), .HREF = oItemRead("href")})
Loop
End Sub
Private Class linkItem
Private m_CatID As Integer
Private m_DName As String
Private m_HREF As String
Public Property CatID() As Integer
Get
CatID = m_CatID
End Get
Set(value As Integer)
m_CatID = value
End Set
End Property
Public Property DName() As String
Get
DName = m_DName
End Get
Set(value As String)
m_DName = value
End Set
End Property
Public Property HREF() As String
Get
HREF = m_HREF
End Get
Set(value As String)
m_HREF = value
End Set
End Property
End Class
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
My Portal - Test
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageContent" Runat="Server">
<%Dim t As linkItem %>
<%Do While oCatRead.Read()%>
<section class="links">
<h2><%=oCatRead("name") %></h2>
<ul>
<%For each t In liLinks %>
<%If t.CatID = oCatRead("id") Then %>
<li><a href="<%=t.HREF %>"><%=t.DName %></a></li>
<%End If %>
<%Next %>
</ul>
</section>
<%Loop%>
</asp:Content>