Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2005

Tip: Looking for answers? Try searching our database.

Newbie With Database Connection Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
No_So_Clever - 24 Oct 2005 17:04 GMT
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
Jerry H. - 31 Oct 2005 15:31 GMT
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).

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.