I have the following datareader that at the end tries to store an array in a datalist. My problem is nothing is being displayed in the datalist and I believe there should be based on my code. Here is the behind code
Dim selectCMD3 As SqlCommand = New SqlCommand()
selectCMD3.CommandText = "Select monthnumber from timemonths where loginID = '" & Session("whosonline" & "'"
selectCMD3.Connection = dbconn
selectCMD3.CommandTimeout = 30
dbconn.open()
Dim data1 as SqlDataReader = selectCMD3.ExecuteReader()
dbconn.close()
dbconn.open()
data1a.DataSource = selectCMD3.ExecuteReader()
data1a.DataBind()
dbconn.close()
Dim selectCMD4 As SqlCommand = New SqlCommand()
selectCMD4.CommandText = "Select distinct monthnumber from timemonths"
selectCMD4.Connection = dbconn
selectCMD4.CommandTimeout = 30
dbconn.open()
data2a.DataSource = selectCMD4.ExecuteReader()
data2a.DataBind()
dbconn.close()
dbconn.open()
Dim data2 as SqlDataReader = selectCMD4.ExecuteReader()
Dim matchs as boolean
Dim i as Integer = 0
Dim monthnames as array
Do until data2.read()
matchs = false
if data2.Item("monthnumber" = DateTime.Now.Month then
exit Do
end if
Do until data1.read()
if data2.Item("monthnumber" = data1.Item("monthnumber" then
matchs = True
End if
data1.nextresult
loop
if matchs = False Then
monthnames(i) = data2.Item("monthnumber"
i = i + 1
End if
data2.nextresult
loop
showmonth1.DataSource = monthnames
showmonth1.DataBind()
dbconn.close()
Here is the page code.
<p class="errormessages">You are missing the following Timesheets. Please complete your missing Timesheet(s)
as soon as possible. </p>
<p class="maintext"><asp:dataList ID="showmonth1" CellPadding="0" ForeColor="#FF0000" CellSpacing="0" Font-Size="9" Font-Bold="true" BorderColor="#000000" BorderWidth="0" GridLines="none" RepeatColumns="1" RepeatDirection="Vertical" runat="server">
<itemtemplate>
<td align="center" width="75">
<%# Container.DataItem( "monthnames" ) %>
</td>
</itemtemplate>
</aspataList></p>
In data1 the value is
7
in data2 the value is
2
6
7
8
Based on what my code above does (i believe) the values of 2,6 should be stored in the array, but when I go to print the array on the page it doesn't display anything. Can anyone see what I am missing or doing wrong?
Dim selectCMD3 As SqlCommand = New SqlCommand()
selectCMD3.CommandText = "Select monthnumber from timemonths where loginID = '" & Session("whosonline" & "'"
selectCMD3.Connection = dbconn
selectCMD3.CommandTimeout = 30
dbconn.open()
Dim data1 as SqlDataReader = selectCMD3.ExecuteReader()
dbconn.close()
dbconn.open()
data1a.DataSource = selectCMD3.ExecuteReader()
data1a.DataBind()
dbconn.close()
Dim selectCMD4 As SqlCommand = New SqlCommand()
selectCMD4.CommandText = "Select distinct monthnumber from timemonths"
selectCMD4.Connection = dbconn
selectCMD4.CommandTimeout = 30
dbconn.open()
data2a.DataSource = selectCMD4.ExecuteReader()
data2a.DataBind()
dbconn.close()
dbconn.open()
Dim data2 as SqlDataReader = selectCMD4.ExecuteReader()
Dim matchs as boolean
Dim i as Integer = 0
Dim monthnames as array
Do until data2.read()
matchs = false
if data2.Item("monthnumber" = DateTime.Now.Month then
exit Do
end if
Do until data1.read()
if data2.Item("monthnumber" = data1.Item("monthnumber" then
matchs = True
End if
data1.nextresult
loop
if matchs = False Then
monthnames(i) = data2.Item("monthnumber"
i = i + 1
End if
data2.nextresult
loop
showmonth1.DataSource = monthnames
showmonth1.DataBind()
dbconn.close()
Here is the page code.
<p class="errormessages">You are missing the following Timesheets. Please complete your missing Timesheet(s)
as soon as possible. </p>
<p class="maintext"><asp:dataList ID="showmonth1" CellPadding="0" ForeColor="#FF0000" CellSpacing="0" Font-Size="9" Font-Bold="true" BorderColor="#000000" BorderWidth="0" GridLines="none" RepeatColumns="1" RepeatDirection="Vertical" runat="server">
<itemtemplate>
<td align="center" width="75">
<%# Container.DataItem( "monthnames" ) %>
</td>
</itemtemplate>
</aspataList></p>
In data1 the value is
7
in data2 the value is
2
6
7
8
Based on what my code above does (i believe) the values of 2,6 should be stored in the array, but when I go to print the array on the page it doesn't display anything. Can anyone see what I am missing or doing wrong?