Hi everyone .
can you help me in making a log in form for administrator using the accounts from the MySql database .. i want to know the code in connecting database, because i am new in SQl database Programming.. example there are 2 fields in SQL database the Username and Password.. the elements inside the field Username is admin and in Password is asusTek. how can i trigger the user if he enter in the wrong Username and Password in two textbox in the form .... I am Using Visual Studio 2005 and my SQL is SQLExpress Edition with SQL server 2005
.... your help means a lot to me as a newbie in SQL database programming thanks
for any one who can give me a simple code of this .. I will accept your reply without any doubt thanks and god blezzz
Loading
paul danielPosted Jan 19, 2010, 12:35 AM
Try this
Imports System.Net.Sockets
Public Class Form1
Const AppName = "Marky's Livechat System"
Dim clientSocket As New System.Net.Sockets.TcpClient()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtUserName.Focus()
End Sub
Private Sub cmdAuthenticate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAuthenticate.Click
If txtUserName.Text = "" Or txtPassword.Text = "" Then
MessageBox.Show("Please enter the required information to login.", AppName, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim mMySQLConnectionString As String = "Server=localhost;Database=logindata;Uid=root;password =root"
'You will need to change the connection string above to yours
Dim conn As MySqlConnection
Dim dr As MySqlDataReader
Dim cmd As New MySqlCommand
conn = New MySqlConnection()
conn.ConnectionString = mMySQLConnectionString
Try
conn.Open() 'Always a good idea to open the connection in a try/catch block
'Before you were selecting the username and password..
'I changed that to the Status field being that its the field we need.
cmd.CommandText = "SELECT Status FROM members WHERE UserName = ?UserName AND Password = ?Password"
cmd.Parameters.Add(New MySqlParameter("?UserName", txtUserName.Text))
cmd.Parameters.Add(New MySqlParameter("?Password", txtPassword.Text))
cmd.Connection = conn
dr = cmd.ExecuteReader
If dr.HasRows() Then
Form2.Show()
Me.Close()
'I used a datareader to hold the result of the Select Statement
'which will be the status field if the username AND password are CORRECT
'If they UserName and Password are wrong, the datareader will not hold any rows.
dr.Read()
Select Case UCase(dr(0).ToString)
Case Is = "ADMIN"
Dim F2 As New Form2
F2.Show()
Me.Close()
Case Is = "MOD"
Dim F3 As New Form3
F3.Show()
Me.Close()
Case Is = "USER"
Dim F3 As New Form3
F3.Show()
Me.Close()
End Select
Else
MsgBox("Either the User Name or Password are Incorrect. Please try again.", MsgBoxStyle.Information, AppName)
txtPassword.ResetText()
txtUserName.ResetText()
txtUserName.Focus()
End If
Catch myerror As MySqlException
MessageBox.Show("Database Error: " & myerror.Message, AppName, MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, AppName, MessageBoxButtons.OK, MessageBoxIcon.Information)
Finally
'The Finally Section of a Try Catch block will always fire, even when it runs into an exception.
'That makes it a good place to clean up
cmd.Parameters.Clear() 'I always clear my parameters when im done with them just to be safe
conn.Close()
cmd.Dispose()
conn.Dispose()
End Try
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
zoren baybayanPosted Jan 20, 2010, 7:34 PM
my friend ask if you can do it in SQL codes not MySQL, if not i will still thank you, but your help is very much appreciated to us..
for your help can you direct your codes to this email
[email protected]
once again thanks for the help
zoren baybayanPosted Jan 15, 2010, 12:38 AM
Lalit MPosted Jan 14, 2010, 11:34 PM
http://www.daniweb.com/forums/thread6028.html#
http://www.dotnetspider.com/resources/28460-Create-Login-Form-Windows-Application.aspx
Connection string