HelpLaura

I have connected Visual Studio to my access database through the wizard.

I want to create a login form whereby when the user enters the user_id and password it checks to see if those two match in the database, if they do, then they move to the next screen if not an error messgae comes up.

Thanks In advance



Re: Visual Basic Language Login page help needed asap

HelpLaura

I have this query now, to search the database

dim loginchecker As String = "Select login_ID, password FROM tbl_login where login_ID ='" & login.Text &"' and password ='" & password.text & "'"

how to i now carry this out and use the result to detrmine whether they are a valid user. I thought about doing a count on th number of rows, hoever i don't know how to get visual studio to do the query.





Re: Visual Basic Language Login page help needed asap


Re: Visual Basic Language Login page help needed asap

HelpLaura

This thread doesn't decribe how to actually run an sql query.

I have built the query, need to be able to run in on the click of a button.





Re: Visual Basic Language Login page help needed asap

PEng1

I am sorry I was writing my last post at the same time as you. In SQL your query should look something like this:

In the Query Wizard(after adding a Query to your TableAdapter)

SELECT login_ID, password

FROM dbo.tbl_login

WHERE login_ID = @login_ID and password = @Password

Then in you button click event you can do this

tbl_loginTableAdapter1.loginchecker(login.text,password.text)

see this forum for a more indepth explanation of creating the query

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1263159&SiteID=1

Also you don't want a FillBy Query you want a GetBy query that returns just one record

If you need more than this let me know.






Re: Visual Basic Language Login page help needed asap

HelpLaura

i got to the point where it gave me the place to chose the name, i did this, but i get an error saying that

"Error in WHERE clause near '@'. Unable to parse query text"

I never got the option of what query i wanted! Have i done it wrong





Re: Visual Basic Language Login page help needed asap

Cameron-Aust

Several ways in doing this.

1. Use the .net login control, and use .net security for your app
2. Store the data in a table in plain text (or encripted if you want to write the algorithym), and just run something like:
(This isnt actually VB Code, more a general idea on where to go from here)
3. Call Stored Procs from your database which is what the previous fellow suggested seems to be.

<User enters login details and clicks 'submit', and the form passes the info to another (or same if you use pass back in asp.net) asp or aspxpage.>

strUsername = Request.Form("txtUsername")
strPassword = Request.Form("txtPassword")

SELECT Username FROM tblUsers WHERE Username = strUsername AND Password = strPassword

Get the General jist on where this is going Been a while since i did authenticated web apps not using .net security or single sign on :/





Re: Visual Basic Language Login page help needed asap

PEng1

My first guess is that you have a space between the @ and your parameter name make sure that this is not the case. If not then try using parethisis around the parameter expressions like (login_ID = @login_ID)




Re: Visual Basic Language Login page help needed asap

HelpLaura

still getting the same error. Any other suggestions



Re: Visual Basic Language Login page help needed asap

PEng1

Different dataproviders use different syntax try this

Where login_ID = and password =






Re: Visual Basic Language Login page help needed asap

Bruno Yu - MSFT

HelpLaura,

According to your problem, please try the following code:

Private Sub btnOK_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles btnOK.Click

' Make sure the user entered something.

If txtUserName.Text.Length = 0 Then

MsgBox("You must enter a user name", _

MsgBoxStyle.Exclamation)

txtUserName.Focus()

ElseIf txtPassword.Text.Length = 0 Then

MsgBox("You must enter a password", _

MsgBoxStyle.Exclamation)

txtPassword.Focus()

ElseIf PasswordInvalid(txtUserName.Text, _

txtPassword.Text) Then

' The user name/password is invalid.

MsgBox("User name/password invalid", _

MsgBoxStyle.Exclamation)

txtUserName.Focus()

Else

' The user name/password is valid.

DialogResult = DialogResult.OK

End If

End Sub

' Put real validation here.

Private Function PasswordInvalid(ByVal user_name As String, _

ByVal password As String) As Boolean

Return (user_name <> password)

End Function






Re: Visual Basic Language Login page help needed asap

HelpLaura

Thanks for this code, i see where you are coming from here, with the message boxes etc. What i don't see is, where does it do a comparison against the field in my database

If you could guide me on this, it would be great.





Re: Visual Basic Language Login page help needed asap

Bruno Yu - MSFT

HelpLaura,

Sorry for the delay. Actually this code snippet is from vb-helper website. I found another article on this problem on verify a username and password in a database in Visual Basic .NET. I believe this article and sample project can help you with the problem:

http://vb-helper.com/howto_net_password_db.html