Pass Username, Password and Datasource from the user

vbsquire

Member
Joined
Aug 30, 2007
Messages
9
Programming Experience
Beginner
I would really appreciate any help with this. I wrote a simple VB.NET App that creates a table in Oracle and does some basic things like: display the "select * from table" into my data grid and also provides a button to drop the table. Everything works fine, but I am forced to hard code the Oracle Username, Password and Datasource, into the application.
For example:

Dim conn As New OracleConnection("Data Source=ORCL;User ID=system;Password=manager")

Can someone give me some advice, as to how get this information from the end user at runtime through text boxes and then somehow pass this information to the code? I've seen a lot of sample code out there, but since I'm a newbie, it's really hard for me to determine what part of the sample code I can use.

I've learned a lot in the past few weeks from this forum, so I'm hoping that someone here can help with this request. I just think my way is so sloppy and I feel like an idiot hard coding something like this and making the user create a special user acct just for this little test app.

Thanks in advance!!
 
I hope this will help.

Create 3 textboxes for Data Source, User ID and Password, Then on your procedure place three parameters like this:

private sub YourProcedure(ByVal DS as String, ByVal ID as String, ByVal Pass as String)

then assign them to your declaration:

Dim conn As New OracleConnection("Data Source=" + DS + ";UserID=" + ID + ";Password=" + Pass)

I am also a newbie here and I hope this will help you.
 
Still stuck :(

Canopy, would you mind giving me a few more pointers? I added the three textboxes and a button named "Connect". I tried to do what you said (which actually made sense), but I keep getting all kinds of "not declared" errors. Would you happen to have any samples that I can look at?

I really do appreciate your help.
 
When you call your procedure do it like this:

VB.NET:
YourProcedure(txtDataSource.Text.Trim, txtUserID.Text.Trim, txtPassword.Text.Trim)

If this still does not work then give the details of your code and the errors you are receiving and I will gladly help you.
 
My Newbie'ness is showing

Canopy,

I think that I'm just confused about what goes where. I'm going to have to play with this a bit. I did comment out what I already had setup for the connection in my Public Class:
'Dim conn As New OracleConnection("Data Source=ORCL;User ID=system;Password=manager")

Then I added this instead:
Dim Host As String
Dim ID As String
Dim Pass As String

Dim conn As New OracleConnection("Data Source=" + Host + ";UserID=" + ID + ";Password=" + Pass)

My Textboxes are called: txtID, txtPass and txtHost

I just don't know what to add in the button "Connect", that will take what the user typed and translate it into the correct connection string. I'm sure I am missing something really simple. I am getting on a plane, but will be back on this in a few hours. I really appreciate your help on this. :)
 
No problem. I am glad that I am helping you even though I am a newbie myself.

Before you call your connection make sure that you had already equate the values of the textboxes to your variables.

VB.NET:
Host = txtHost.Text.Trim ' Use trim to just to make sure :)
ID = txtID.Text.Trim
Pass = txtPass.Text.Trim
' Then declare your connection
Dim conn As New OracleConnection("Data Source=" + Host + ";UserID=" + ID + ";Password=" + Pass)

Thats it if you are still having problems let me know and I will help you as long as I am available. :)

Jah Bless!!! :D

Drop Seeds and not your Bombs, Show your Love and not your Arms.
 
For a more modern/sensible way to build strings from several variables, see String.Format in the documentation

Stirng.Format("src={0};uid={1};pwd={2};myDate={3:yyyyMMdd};myNum={4:0.00}", datSource, usernamebox.Text, passwordBox.Text, DateTime.Now, myDouble)

This looks much neater than classic string concat and offers a variaety of formatting options to boot
 
Wow, thanks so much Canopy and System! I will work with the recommendation from Candopy first and if I master that, I will try substituting the string with the other one. I will be back soon!

Thanks again!
 
Thanks!

It worked! Thanks so much for your help Canopy and for the suggestions. They made all the difference in the world.
 
No problem man!

Jah Bless!!! :D


Drop Seeds and not your Bombs, Show your Love and not your Arms.
 
Back
Top