ConnectionString

N

No_So_Clever

Hi I have the following for My Database connection in my project:

Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=J:\Database\MasterDB.mdb"
UP.Connection = Con
UP.CommandType = CommandType.Text
UP.CommandText = "Select * From Passwords Where Users_Name=? and
Users_Password=?"

I`ve now want to use a connection class of (Allowing me use choose a
Database to Use):

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("D:\Database\MasterDB.mdb")
connArray.Add("D:\Database\LocalDB.mdb")
'Use For Debugging DB Connection Errors
'MessageBox.Show(ind.ToString())
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

I know I need to change my "Con.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\Database\MasterDB.mdb" I
thought it would be changed to:

Con.ConnectionString = Me.cboSelectDB.SelectedIndex but then it tells me
"Option Strict On disallows implicit conversions from 'Integer' to 'String'"
if I take Options Strict On off it errors and says: "Format of the
initialization string does not conform to specification starting at index
0."

Could somebody kindly point me in the right Direction for a fix?

Many Thanks
NSC
 
M

Mark Rae

Con.ConnectionString = Me.cboSelectDB.SelectedIndex but then it tells me
"Option Strict On disallows implicit conversions from 'Integer' to
'String'" if I take Options Strict On off it errors and says: "Format of
the initialization string does not conform to specification starting at
index 0."

Could somebody kindly point me in the right Direction for a fix?

There is no fix because there's nothing wrong - your code is returning you
PRECISELY what you asked for.

SelectedIndex returns an integer representing the element of the Items array
which is currently selected - nothing whatever to do with the value or text
of that Item. If you populate a combobox with the twelve months of the year
in chronological order (i.e. January, February, March etc) and select
December, the SelectedIndex will be 11.

Put a breakpoint on the above line and then interrogate Me.cboSelectDB in
the Command window - you'll soon see which property you need.
 
W

W.G. Ryan - MVP

Cor:

I'm not following you here, where does SelectedValue fit in?
Cor Ligthert said:
No_So_Clever

Try SelectedValue

I hope this helps,

Cor


No_So_Clever said:
Hi I have the following for My Database connection in my project:

Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=J:\Database\MasterDB.mdb"
UP.Connection = Con
UP.CommandType = CommandType.Text
UP.CommandText = "Select * From Passwords Where Users_Name=? and
Users_Password=?"

I`ve now want to use a connection class of (Allowing me use choose a
Database to Use):

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("D:\Database\MasterDB.mdb")
connArray.Add("D:\Database\LocalDB.mdb")
'Use For Debugging DB Connection Errors
'MessageBox.Show(ind.ToString())
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

I know I need to change my "Con.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\Database\MasterDB.mdb" I
thought it would be changed to:

Con.ConnectionString = Me.cboSelectDB.SelectedIndex but then it tells me
"Option Strict On disallows implicit conversions from 'Integer' to
'String'" if I take Options Strict On off it errors and says: "Format of
the initialization string does not conform to specification starting at
index 0."

Could somebody kindly point me in the right Direction for a fix?

Many Thanks
NSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top