Hi all,
I'm new to VB and need some help im trying to get a form to load after a login box below is the code im using so far. Also is there any way i could get the login box to check a database for the usernames and passwords before alowing login
If
Usrname.Text = ("greg") And Password.Text = ("password") And Domain.Text = ("United Kingdom") ThenIm not sure what goes on the end of then.
Thanks,
Greg Thomas

Need help with loading a form.
Sebastian Dev
GregBowie
Thanks for that advice i have used the main.show () to open the next window after the login have been authenticated.
Where would i place the SQL connection string would that be in the same place as the button code or would it go in to the main program code
Cheers.
Kevin Schlegelmilch
Hi!
When you check login - you can open new form by creating form object and calling Show().
To close current form - you can use "DialogResult = DialogResult.OK".
To check database you can try something like this (I have C# sample only):
void DoCheck(){
try{
using (SqlConnection con = new SqlConnection(ConnectionString)){
}
// all ok here
} catch (SqlException ex){
}
}
If you need to build connection string - there is ConnectionStringBuilder class that can help.
zhu.zheng
I'm new with vb too and have been creating data connections through access.
Do you have a data connection setup
If not, go to the tab under the soultion explorer window and click the tab entitled data sources.
Then click the hyperlink that says "Add new connection..." or something like that. This wizard should help you set up a connection. Just choose database on the first screen and on the second screen you should be able to choose your provider (SQL 2005).
The wizard may ask you if you want to make a copy of your database to your project folder...Make sure you select no, especially if you wnat to be able to make changes to the database.
I'm sorry if this isn't too clear since I don't have visual studio here with me. But this should hopefully get you started in the right direction of connection your database to your application.
Hope this was helpful,
Chris
Yoshifumi INOUE
And, what version of VS are you running
Harreld Kuiper
I'm C# programmer, my typical app with login looks like this:
void Main()
{
}
Login form must set "DialogResult = DialogResult.OK;" to confirm that it pass login phase.
Connection string you can add in project properties (settings) or using Data Sources. But if you want to know all about them and have best control over connection - SqlConnectionStringBuilder class must be used. Check MSDN for it. I use it to test connection before app start and in case database server not found (or other problem) I give user a chance to enter new server/login/password for connection.
Where to put code - no matter. All depends on design of your app. I put it right inside form and this is ok. If you have big layered project - put in Data Access Layer.
Prof
Here's a general idea of what your going to need to do... I'n the example I'll refer to the the two forms as login form and firstform where when you enter details and click a button on the login form it will display the firstform.
Login Form - will contain a button. In the button click event you will have code that values that the appropriate textbox Field Values are set.
If Usrname.Text = ("greg") And Password.Text = ("password") And Domain.Text = ("United Kingdom") Then
Dim ObjFirstForm as new FirstForm
ObjFirstForm.Show
End If
The will cause an Object to be created of type FirstForm - which is name of the the first form you want to display
.Show causes it to be displayed non - modally
You'll probably want to get rid of the login form once the First Form has been displayed. So you may chnage around the code a little
If Usrname.Text = ("greg") And Password.Text = ("password") And Domain.Text = ("United Kingdom") Then
Dim ObjFirstForm as new FirstForm
ObjFirstForm.Show
Me.Close 'Close the current Form
End If
Me.Close will close the current form - which will be the login form. So you'll end up with just the firstform loaded when you click a button and all the textbox fields are set to the hardcoded values you specified.
In Order to check the database you would write a simple function that will take the parameters Username, Password, Domain and create a simple call to a database stored procedure / query that would return true/false depending upon the details macthed a record in database or not.
To start out with I'd create the function - and put the hardcoded values into this function and then you can simply replace the validation routine to a database one later - this means that you validation code is encapsulated within a single function and whereever you want to validate user credentials you simply call this method.