|
||
|
|
#1 (permalink) |
|
Join Date: Jun 2006
Posts: 1
|
I've been trying to make my own login/registration system in vb.net, with not too much luck. I got most of my information from www.vbmysql.com, but still haven't been able to complete the login form. I'm trying to connect to the database, users, and the table user. Right now, I'm just trying to retrive the username data and compare it. I'm hopelessly lost now, and on the verge of giving up. Please help me!
Below is a small piece of my code. Code:
If user.Text = "" Then
MsgBox("Enter a Username!")
Else
If pass.Text = "" Then
MsgBox("Enter a Password!")
Else
conn = New MySqlConnection()
conn.ConnectionString = "server=localhost; user id=root; password=; database=users"
End If
Try
conn.Open()
sSQL = "SELECT * FROM user where user= '" & user.Text & "'"
conn.Close()
If sSQL = user.Text Then
MsgBox("Success!")
work = 1
End If
Catch myerror As MySqlException
*** Rest of the code ***
|
|
|
|
|
|
#3 (permalink) | |
|
Forum Novice
Join Date: Jul 2004
Location: Switzerland
Age: 25
Posts: 234
|
Quote:
The assignment of a query to the string sSQL doesn't execute the query, so If sSQL = user.Text Then compares to the SELECT[...] string, which failes unless the user writes exatly this sentence into the textbox. Please take a look on the MySQLCommand class on how to execute a MySQLReader Query. something like this: (not tested, written right of my mind) Code:
If user.Text = "" Then
MsgBox("Enter a Username!")
Else If pass.Text = "" Then
MsgBox("Enter a Password!")
Else
conn = New MySqlConnection()
conn.ConnectionString = "server=localhost; user id=root; password=; database=users"
Try
conn.Open()
sSQL = "SELECT * FROM user where user LIKE '" & user.Text & "' AND password = '" & pass.Text & "'"
Dim command As MySQLCommand = new MySQLCommand( conn, sSQL )
Dim reader As MySQLReader = command.ExecuteReader()
While reader.Read()
If reader("user").ToString() = user.Text Then
MessageBox.Show("Success!") ' do NOT use the Microsoft.VisualBasic namespace, except in legacy code!
work = 1
End If
Loop
conn.Close()
Catch myerror As MySqlException
End If
*** Rest of the code ***
![]() |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|