AltaSens
asked on
VB2008: IndexOutOfRangeException was unhandled when attempting to read values from SQL into a list collection
I am attempting to load a single column of data from a SQL Server table into a list.collection and when I execute the code, I receive the error message "IndexOutOfRangeException was unhandled".
I played around with the idea of using an array but went with a list collection because :
1. as I understand it, a list is dynamic and can resize itself automatically
2. adding items to a list seem simpler and can be done without having to create a for-next loop which I am unsure how to code
The code segment is shown below --------------------------
Public ProjectList As New List(Of String)(100)
connection.Open()
Dim reader As SqlDataReader = selectCommand.ExecuteReade
'ProjectList = New String(intNumRows) {}
Do While reader.Read
'ProjectList.Add(reader("P
Debug.Write(reader("Projec
Loop
MsgBox("Error in Form.Initialize module" & vbCr & vbCr & "Please record this error message and contact the IT Helpdesk", vbExclamation, "ProjecTrack : Error")
Close()
Catch ex As SqlException
Throw ex
Finally
connection.Close()
End Try
Although I don't understand much of this, the exception detail is listed below --------------------------
System.IndexOutOfRangeExce
Message="ProjectName"
Source="System.Data"
StackTrace:
at System.Data.ProviderBase.F
at System.Data.SqlClient.SqlD
at System.Data.SqlClient.SqlD
at ProjecTrack.frmTimeEntry.f
at ProjecTrack.frmTimeEntry.T
at System.EventHandler.Invoke
at System.Windows.Forms.Form.
at System.Windows.Forms.Form.
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Scrol
at System.Windows.Forms.Conta
at System.Windows.Forms.Form.
at System.Windows.Forms.Form.
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Nativ
at System.Windows.Forms.SafeN
at System.Windows.Forms.Contr
at System.Windows.Forms.Form.
at System.Windows.Forms.Contr
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at Microsoft.VisualBasic.Appl
at Microsoft.VisualBasic.Appl
at Microsoft.VisualBasic.Appl
at ProjecTrack.My.MyApplicati
at System.AppDomain._nExecute
at System.AppDomain.nExecuteA
at System.Runtime.Hosting.Man
at System.Runtime.Hosting.Man
at System.Runtime.Hosting.App
at System.Runtime.Hosting.App
at System.Activator.CreateIns
at Microsoft.VisualStudio.Hos
at System.Threading.ThreadHel
at System.Threading.Execution
at System.Threading.ThreadHel
InnerException:
--------------------------
I appreciate any guidance you can provide. THANK YOU!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.