The following code is my attempt to dynamically set the size of an array and then to dynamically assign values to it. However it is incomplete and I could do with some assistance.
Any feedback would be appreciated.
If someone could complete the missing links in the code I would be very thankful.
Dim MyArray() As Integer
Dim nCountOfRecords As Integer
Dim I As Integer
Dim cnn As String = (ConfigurationSettings.AppSettings("SomeWebSite"))
Dim objConnection as new sqlConnection(cnn)
Dim objCommand as new SqlCommand("procThatCountsTheIDs", ObjConnection)
objCommand.CommandType = CommandType.StoredProcedure
Dim ObjCountRecords as new SqlParameter("@ObjCountRecords",SqlDbType.int)
ObjCountRecords.Direction=ParameterDirection.Output 'Gets the value that will be the array size
Catch ex as Exception
Response.Write("Error:" & ex.Message & "<br/>")
' Assign the number of records to the 'nCountOfRecords' variable
nCountOfRecords =(ObjCommand.Parameters("@ObjCountRecords").Value) 'Should this be... (ObjCommand.Parameters("@ObjCountRecords").Value)-1.....?
ReDim MyArray(nCountOfRecords) ' re-dimension as needed
'It seems to me, the following code dynamically sets the size of the array so do I need to do another DbQuery and then assign the actual IDs to the array?
For I = 1 To nCountOfRecords
MyArray(I) = I '<- this will a assign I to MyArray
'So now I need some code that assigns the ID to the newly created array
'So code here.............
'Now display ....say....MyArray(4) and MyArray(22)
'Just use a couple of labels or something.