I need code for login verification form,
which gets the username and password from the user and verify it in database(sql server) ,if its correct means connect to next form.

help me plsss
durai

Recommended Answers

All 3 Replies

A modal dialog which requires user to set his/her username and password when s/he i.e press Login call method to connect to SQL Server verfiy using try...catch
try->login successed, else login failed

hi,

Use the below coding
Sql Server Connection
Dim con As SqlConnection = New SqlConnection("server=shailu;uid=sa;pwd=;database=master")
Try
con.Open()
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "select count(*) from login where username = '" & TextBox1.Text & "' and password = '" & TextBox2.Text & "'"
cmd.Connection = con
Dim i As String = cmd.ExecuteScalar
If i = "0" Then
MsgBox("Unknown Username and Password")
TextBox1.Text = ""
TextBox2.Text = ""
Else
Dim f1 As New Form1
f1.Show()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

Best Regards
Shailu:)


I need code for login verification form,
which gets the username and password from the user and verify it in database(sql server) ,if its correct means connect to next form.

help me plsss
durai

try using this set of code.....
adn remeber your load from should contain
this......

UP.Connection = Con
UP.CommandType = CommandType.Text
UP.CommandText = "Select * From tablename Where user=? and password=?"
..............
If UsersNameTextBox.Text.Trim = "" Then
MessageBox.Show("Please fill your User Name !", _
"Password", MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
UsersNameTextBox.Focus()
Exit Sub
End If

'if textbox2 is blank then ...
If PasswordTextBox.Text.Trim = "" Then
MessageBox.Show("Please fill your Password !", _
"Password", MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
PasswordTextBox.Focus()
Exit Sub
End If

'Admin
UP.Parameters.Add("user", Data.OleDb.OleDbType.Variant)
UP.Parameters.Add("password", Data.OleDb.OleDbType.Variant)

UP.Parameters("user").Value = UsersNameTextBox.Text
UP.Parameters("password").Value = PasswordTextBox.Text

'Open database connection
Con.Open()

' Read information from database
Read = UP.ExecuteReader

ar()

' Close database connection
Con.Close()


End Sub
Private Sub ar()
With Read
If .Read Then

Me.Hide()
'Put your Form here
CurrentForm = New information()
CurrentForm.Show()

Else
Plus += 1

If Plus >= 3 Then
MessageBox.Show("Sorry, too many error !", _
"Password", MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
'Close application
End
Else

UsersNameTextBox.Clear()
PasswordTextBox.Clear()


MessageBox.Show("Invalid User Name or Password !", _
"Password", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End If
End If
UsersNameTextBox.Focus()
End With
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.