Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

working with datareader and arrays

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
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=&quot;errormessages&quot;>You are missing the following Timesheets. Please complete your missing Timesheet(s)
as soon as possible. </p>
<p class=&quot;maintext&quot;><asp:dataList ID=&quot;showmonth1&quot; CellPadding=&quot;0&quot; ForeColor=&quot;#FF0000&quot; CellSpacing=&quot;0&quot; Font-Size=&quot;9&quot; Font-Bold=&quot;true&quot; BorderColor=&quot;#000000&quot; BorderWidth=&quot;0&quot; GridLines=&quot;none&quot; RepeatColumns=&quot;1&quot; RepeatDirection=&quot;Vertical&quot; runat=&quot;server&quot;>
<itemtemplate>
<td align=&quot;center&quot; width=&quot;75&quot;>
<%# Container.DataItem( &quot;monthnames&quot; ) %>
</td>
</itemtemplate>
</asp:DataList></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?
 
Why open connection, execute the command object and close connection twice in sucession?

dbconn.open()
Dim data1 as SqlDataReader = selectCMD3.ExecuteReader()
dbconn.close()
dbconn.open()
data1a.DataSource = selectCMD3.ExecuteReader()
data1a.DataBind()
dbconn.close()
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
I did this just to make sure they were returning values, but when I had this second one out of there it still didn't work.
 
Here is what they look like

Dim selectCMD3 As SqlCommand = New SqlCommand()
selectCMD3.CommandText = &quot;Select monthnumber from timemonths where loginID = '&quot; & Session(&quot;whosonline&quot;) & &quot;'&quot;
selectCMD3.Connection = dbconn
selectCMD3.CommandTimeout = 30
dbconn.open()
Dim data1 as SqlDataReader = selectCMD3.ExecuteReader()
dbconn.close()

Dim selectCMD4 As SqlCommand = New SqlCommand()
selectCMD4.CommandText = &quot;Select distinct monthnumber from timemonths&quot;
selectCMD4.Connection = dbconn
selectCMD4.CommandTimeout = 30
dbconn.open()
Dim data2 as SqlDataReader = selectCMD4.ExecuteReader()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top