dotnet windows forms databinding:
Hi, Wonder if Somebody could help me? I`ve been searching all over for a solution but am totally lost. I have a Class called Connection as below: Public Class Connection Private Shared mConnectionsstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" Private Shared mLocation As String Private Shared connArray As ArrayList Public Shared Sub setString(ByVal ind As Integer) Dim connArray As New ArrayList connArray.Add("J:\Database\MasterDB.mdb") connArray.Add("J:\Database\TestDB.mdb") mLocation = connArray(ind).ToString End Sub Public Shared ReadOnly Property [String]() As String Get Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mLocation & ";" End Get End Property End Class On my Main Form I have my Database Connection Setup as: Dim UP As New OleDb.OleDbCommand() Dim Con As New OleDb.OleDbConnection() Connection.setString(Me.cboSelectDB.SelectedIndex) Con.ConnectionString = Connection.String UP.Connection = Con UP.CommandType = CommandType.Text UP.CommandText = "Select * From Passwords Where Users_Name=? and Users_Password=?" End Sub But when I run my App it Errors on line "mLocation = connArray(ind).ToString" with the following error: "Additional information: Index was out of range. Must be non-negative and less than the size of the collection" Anybody point me in the right direction? Many Thanks in Advance Regards Not_So_Clever
Either your ConnArray has no elements in it, or the value of "ind" is greater than the number of elements that are in ConnArray. Remember, Arrays are Zero-indexed, so when reference elements in them, start at Zero. In your example, you should only be able to get a value if "ind" is equal to "0" or "1" (unless you have code else that also adds to connArray) Put a breakpoint on your mLocation line, and check the value of "ind", and also connArray.Count. "Ind" can be no greater than (connArray.count-1).
Don't see what you're looking for? Try a search.
|