0

Im making a program that uses an MySql database.

Right now i am using Visual Basic and Visual Studio 2013, and i am pretty new to programming. Other than html, css, javascript, and some php.

Now i want to use 2 textboxes to insert username and password to the connection string. So:

server=IP ADRESS;userid="TextBox4 input";password="TextBox1 input";persistsecurityinfo=True;database=DB

This is pretty much the connection string i have now. Just with all the info so everyone can see them. Now at the user id and password i want to be able to use 2 different textboxes to insert the data in there.

Anyone who has an idea how to do that?

THIS is my connection string right now. In project/projectname properties/settings.

Thanks in advance!

3
  • You want to use TextBox4.Text for both, the userid and the password? Commented Sep 7, 2015 at 9:29
  • No, sorry userid=textbox4 password=textbox1 Commented Sep 7, 2015 at 11:08
  • Here goes Captain Obvious - In the picture, it does not work because there is no user id as well as a password. This is where the input from the TextBoxes will go. Commented Sep 7, 2015 at 12:47

2 Answers 2

2

You can use a MySqlConnectionStringBuilder:

Dim conBuilder As New MySql.Data.MySqlClient.MySqlConnectionStringBuilder()
conBuilder.Server = "IP ADRESS"
conBuilder.PersistSecurityInfo = True
conBuilder.Database = "DB"
conBuilder.UserID = txtUserID.Text
conBuilder.Password = txtPassword.Text
Dim connectionString = conBuilder.ToString()

Note that i've renamed your textboxes to something more meaningful.

Sign up to request clarification or add additional context in comments.

3 Comments

But i am using the wizard to connect to my MySql database. Not a connection string in the form1 code. Will i be able to use this for it still?
@Thomsen1707: where and for what do you use the connection-wizard? You can use my code without wizard. Just assign the connection-string to the object for which you need the connection-string, f.e. a MySqlConnection. No wizard needed.
Yea should have said - in visual studio 2013 in data sources. Felt much more easy
0
Dim conn As New MySqlConnection
conn .ConnectionString = "server=IP ADRESS; " & _
                         "userid=" & Trim(txtUserName.Text) & "; " & _  /*'put your textbox name that holds username */
                         "password=" & Trim(txtPassWord.Text) & ";" & _  /*'put your textbox name that holds password */
                         "persistsecurityinfo=True;" & _
                         "database=DB"

7 Comments

This works when i just do a conn.open(). But how do i use this data in my DataGridViews?
@Thomsen1707 just elaborate how do i use this data in my DataGridViews? , what data a conn? or user/pwd ?
I need to put data from my MySql database inside a DataGridView. Not user/pwd, but some stock data. How do i put this data inside the DataGridView with code?
@Thomsen1707 From your comments what I understood is You have to declare connection string as a global variable so that It could access when you need to declare a connection to access data from DB
Revamp your question with actual need and put code from where you want to fetch usr/pwd
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.