pgilfeather
asked on
I am trying to pull a column of ID numbers into the array and then be able to display an arbitrary array value.
The following code wont run it keeps assigning 0 to lblCount.Text. Any Ideas?
I am trying to pull a column of ID numbers into the array and then be able to display an arbitrary array value.
Sub createArray(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim cnn2 As String = (ConfigurationSettings.App Settings(" SomeWebSit e"))
Dim objConnection2 as new sqlConnection(cnn2)
objConnection2.Open()
Dim objCommand2 as new SqlCommand("procThatPullsI DsFromTabl e", ObjConnection2)
objCommand2.CommandType = CommandType.StoredProcedur e
objCommand2.Connection = ObjConnection2
Dim objreader As SqlDataReader = objCommand2.ExecuteReader( )
ReDim MyArray(countIDs) 'countIDs is set in a different section of code
Do While objreader.Read()
For I = 1 to countIDs
ReDim MyArray(I)
MyArray(I) = objreader.GetInt32(0)
Next
Loop
lblCount.Text = MyArray(2) 'Display one of the values of the array
objConnection2.close()
End Sub
I am trying to pull a column of ID numbers into the array and then be able to display an arbitrary array value.
Sub createArray(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim cnn2 As String = (ConfigurationSettings.App
Dim objConnection2 as new sqlConnection(cnn2)
objConnection2.Open()
Dim objCommand2 as new SqlCommand("procThatPullsI
objCommand2.CommandType = CommandType.StoredProcedur
objCommand2.Connection = ObjConnection2
Dim objreader As SqlDataReader = objCommand2.ExecuteReader(
ReDim MyArray(countIDs) 'countIDs is set in a different section of code
Do While objreader.Read()
For I = 1 to countIDs
ReDim MyArray(I)
MyArray(I) = objreader.GetInt32(0)
Next
Loop
lblCount.Text = MyArray(2) 'Display one of the values of the array
objConnection2.close()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the more likely problem was the loop inside the while loop.
Whoops. Lets try that again. REMOVE the ReDim from inside the loop. You have already sized the array outside the loop.
Do While objreader.Read()
MyArray(I) = objreader.GetInt32(0)
Loop
Do While objreader.Read()
MyArray(I) = objreader.GetInt32(0)
Loop
Whoops again...make that:
Dim ii As Integer = 0
Do While objreader.Read()
MyArray(ii) = objreader.GetInt32(0)
ii += 1 'Increment ii counter
Loop
Dim ii As Integer = 0
Do While objreader.Read()
MyArray(ii) = objreader.GetInt32(0)
ii += 1 'Increment ii counter
Loop
isnt that what I said ?
Hmmm...guess I didn't refresh my browser enough! 8-|
Sub createArray(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim cnn2 As String = (ConfigurationSettings.App
Dim objConnection2 as new sqlConnection(cnn2)
objConnection2.Open()
Dim objCommand2 as new SqlCommand("procThatPullsI
objCommand2.CommandType = CommandType.StoredProcedur
objCommand2.Connection = ObjConnection2
Dim objreader As SqlDataReader = objCommand2.ExecuteReader(
ReDim MyArray(countIDs) 'countIDs is set in a different section of code
dimi as integer i = 0
Do While objreader.Read()
MyArray(I) = objreader.GetInt32(0)
i+= 1
Loop
lblCount.Text = MyArray(2) 'Display one of the values of the array
objConnection2.close()
End Sub