I am trying to build a login page in asp.net with sql as backend ,
when i enter the username and password and click the submit , nothing happens.. Please help

this is my *.aspx.vb file........

Imports System.Data.SqlClient
Imports System.Data

Partial Class login1
Inherits System.Web.UI.Page

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim un As String
Dim _password As String
un = TextBox1.Text
Dim myConn As New SqlConnection
myConn.ConnectionString = ConfigurationManager.ConnectionStrings("Team13ConnectionString").ToString

Dim myCommand As New SqlCommand
myCommand.Connection = myConn

myCommand.CommandType = Data.CommandType.Text
Dim MyQuery As String
MyQuery = "SELECT pwd FROM TUser WHERE UserId='" & un & "'"
myCommand.CommandText = MyQuery
myCommand.Parameters.Add(un, SqlDbType.NVarChar, 50).Value = TextBox1.Text
'//use add with value to specify which object you want to use

Dim adapt As New SqlDataAdapter

adapt = New SqlDataAdapter(myCommand)

'//load data to datatable
Dim dt As New DataTable



Dim a As DataRow
'//get Password on Datatable
For Each a In dt.Rows
_password = a("pwd").ToString()

'//Check password

If (_password = TextBox2.Text) Then


End If

End Sub
End Class

Recommended Answers

All 3 Replies

For a start make things easier on yourself and check in your SQl for a user name AND password. Then you don't need to do the second check, if the query returns a row you know the credientials are OK.

Have you debugged your code? If you think an error is being thrown use a try/catch block to see what it is. It can remove a lot of the guess work even if you remove it later.

Okay like @hericles pointed above that code is too much for checking available of a user.Make sure the primary key field of your table is entered by the user as part of the log in info.Use the primary key to retrieve the row of the respective user.If not row ids returned the user is not registered-take necessary action.if a row is returned proceed to services.aspx.

I don't know about that connectionstring u r using.Try:

.connectionsdtring="Data source=your server name;innitial catalog=database name;integrated security=true"

The issues you have is with your select statement. Fist you check for the user and then later in your datarow you check for password. Also, i advice you learn to name controls appropriately not just to help yourself but also help other programmers reading your code.

Imports System.Data
Imports System.Data.SqlClient

Public Class login1
Inherits System.Web.UI.Page

    Private Sub signInButton_Click(sender As System.Object, e As System.EventArgs) Handles signInButton.Click

            ConnectionString.ConnSQL() 'call connection string 

            Dim selectString As String = "SELECT * FROM USERS WHERE UserName = '" + userNameTextBox.Text + "' AND Password = '" + passwordTextBox.Text + "'"

            Dim dc As SqlCommand = New SqlCommand(selectString, ConnectionString.ConnSQL)

            Dim reader As SqlDataReader = dc.ExecuteReader

            If reader.Read Then

                'set action on sucessful authentication

		'display error message

        Catch ex As Exception
        End Try

    End Sub

End Class
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.