Link to home
Start Free TrialLog in
Avatar of alucky8ball
alucky8ballFlag for United States of America

asked on

VB 2005 How to change My.Settings Connection String

I have searched and found several threads on changing the connection string values in VB 2005, but have yet to find an easy way to do it.  Also, as an alternative I tried writing the connection string into an XML file, but the string would never let me connect.  Has anyone had any luck with storing a connection string in a manner that it can be easily changed in the event the datasource changes?
ASKER CERTIFIED SOLUTION
Avatar of Hawkvalley1
Hawkvalley1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Accually the single quotes are needed in queries, they should not be needed in your connection string.
Avatar of alucky8ball

ASKER

I'm sorry, but what does the '{0}' refer to?
- Whatever string is in your textbox, or any other place you can draw the string from.
If textbox1.text is "something" then when you write:
 Dim con As String = String.Format(" your path to your server... '{0}'... ", txtdatabaseSource)' it will be
                                                       " your path to your server... something ..."
It just adds the string inside of your connection string. I know this may seem weird(and it might be) but this will work as long as the info is right. After all it is just a string, and this is a simple manipulation of that string.
{0} is the first value, {1} is the second value, etc... and you can reuse the {X} as many times as you need.
" The {0} day is always the {1}!", txt1.text, txt2.text) = "The first day is always the hardest" where
txt1.text = "first" and txt2.text = "hardest"
These could also be comboBox1.selected.item.tostring just as well!

Happy coding...
For clarity sake line 3(above) should have looked like
Dim con As String = String.Format(" your path to your server... {0}... ", textbox1.text)' it will be...

Also I have not tested this for your purposes, hope this is something you can do easily enough, and to reiderate you will not need the single quotes around the braces {}, unless you use this method in a sql statement.

Dim sql as string = Format("SELECT * FROM myTable WHERE column1 = '{0}' OR '{1}' ", txt1.text, txt2.text)

Makes an interface for custom searching.