c# window login form application
I want to create c# window login form application and I want that login form to connect to my SQL database and open the second form. I tried most tutorials but is failing to connect to my database. Please help
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vincent Maverick DuranoPosted Jul 10, 2018, 7:50 PM
abra manPosted Jul 10, 2018, 11:36 AM
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
End Class
abra manPosted Jul 10, 2018, 10:44 AM
Rafnas T PPosted Jul 10, 2018, 10:09 AM
Vincent Maverick DuranoPosted Jul 9, 2018, 5:23 PM
abra manPosted Jul 9, 2018, 11:47 AM
Dim da As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim sqlquery As String
Private Sub frmLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.ConnectionString = "Data Source=ABRAM-PC\SQLEXPRESS;Initial Catalog=Login;Integrated Security=True"
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Try
'checking if the username and password field is null
If Len(Trim(txtUserName.Text)) = 0 Then
MessageBox.Show("Enter the user name", "Input Error !", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
txtUserName.Focus()
End If
If Len(Trim(txtPass.Text)) = 0 Then
MessageBox.Show("Enter the password", "Input Error !", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
txtPass.Focus()
End If
'executing SQL Query for retrieving the username and password from the database table
con.Open()
sqlquery = "SELECT * FROM LoginTable WHERE user_name='" & txtUserName.Text & "' and password='" & txtPass.Text & "' "
da = New SqlClient.SqlDataAdapter(sqlquery, con)
da.Fill(ds, "LoginTable")
If ds.Tables("LoginTable").Rows.Count <> 0 Then
MessageBox.Show("Login succeed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Invalid user name and password", "Access denied", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
con.Close()
clear() 'calling clear method here
Catch ex As Exception
MessageBox.Show(ex.Message, "Exception generated", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
' declaring a method for clearing the controls
Public Sub clear()
txtPass.Clear()
txtUserName.Clear()
End Sub
' code for show password
Private Sub chkshowpass_CheckedChanged(sender As Object, e As EventArgs) Handles chkshowpass.CheckedChanged
If chkshowpass.Checked = True Then
txtPass.UseSystemPasswordChar = False
Else
txtPass.UseSystemPasswordChar = True
End If
End Sub
End Class
rajendra singhPosted Jul 8, 2018, 11:18 PM
Rafnas T PPosted Jul 8, 2018, 10:42 PM
Ranjit PowarPosted Jul 8, 2018, 10:27 AM