|
-
Sep 7th, 2011, 05:02 PM
#1
[RESOLVED] Oledb Login Form
I'm making a window's application project, and I'm trying to make a login page. First time trying, and I think I'm getting somewhere. Just keep running into a few things. Here is my code:
Code:
Imports System.Data.OleDb
Public Class Form4
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Do you want to not login?"
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "?"
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
Me.Close()
If response = MsgBoxResult.No Then
IDTextBox.Clear()
PasswordTextBox.Clear()
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim na As String
Dim ne As String
Dim ni As String
Dim read As OleDbDataReader
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= ./login.mdb;Jet OLEDB")
Dim cmd As OleDbCommand = New OleDbCommand("Select * from login where First_NameTextBox.Text = '" & PasswordTextBox.Text & "' ", cn)
cn.Open()
read = cmd.ExecuteReader
If read.HasRows Then
read.Read()
na = read("AdminName")
ni = read("AdminPass")
If (First_NameTextBox.Text = na And PasswordTextBox.Text = ni) Then ne = na
Form1.Show()
Me.Hide()
Else
MsgBox("Incorrect Username/Password")
First_NameTextBox.Clear()
PasswordTextBox.Clear()
End If
Catch
MsgBox("Error logging in, please try again", MsgBoxStyle.Exclamation)
End Try
End Sub
End Class
The problems I run into are:
my textbox.clear isn't clearing. The text stays
when I try debugging the program and enter my first name and password, it gives me the "error logging in, please try again" and I know that test/test is the first name and password :P is there anything you notice that I should do?
-
Sep 7th, 2011, 05:54 PM
#2
Re: Oledb Login Form
your select statement is wrong. it should be something like this:
vb Code:
"SELECT * FROM login WHERE fieldName = '" & First_NameTextBox.Text & "' AND otherFieldName = '" & PasswordTextBox.Text & "'"
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 8th, 2011, 11:12 AM
#3
Re: Oledb Login Form
In the sql statement, is it [first name] or first_name for the field name?
-
Sep 8th, 2011, 11:36 AM
#4
Re: Oledb Login Form
 Originally Posted by .paul.
your select statement is wrong. it should be something like this:
vb Code:
"SELECT * FROM login WHERE fieldName = '" & First_NameTextBox.Text & "' AND otherFieldName = '" & PasswordTextBox.Text & "'"
Heck, I'll go a step further an throw in parameters....
vb Code:
"SELECT * FROM login WHERE fieldName = ? AND otherFieldName = ?"
Then use the .Parameters.AddWithValue method to add the values... just be sure to do it in the right order.
If you want to know why you should use parameters... you never know when Bobby Drop Tables will try to login - http://xkcd.com/327/
 Originally Posted by dday9
In the sql statement, is it [first name] or first_name for the field name?
Huh? You tell us... it's your table structure... not ours...
-tg
-
Sep 8th, 2011, 04:19 PM
#5
Re: Oledb Login Form
Huh? You tell us... it's your table structure... not ours...
I thought that you had to do [first name] in oledb if there's a space in your field name. But it's w/e I just added a loginform and added this:
Code:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If Me.UsernameTextBox.Text = "admin" And Me.PasswordTextBox.Text = "admin" Then
Form1.Show()
Me.Close()
Else
MsgBox("Invalid username or password.")
PasswordTextBox.Text = ""
UsernameTextBox.Select(0, UsernameTextBox.Text.Length())
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close() '***** msgboxes!
End Sub
If I have any other questions, I'll just post another thread. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|