Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports System.Data.SqlClient.SqlConnection
Imports System.Data.SqlClient

Public Class login11
    Inherits System.Web.UI.Page
    Public Function Validate_Login(ByVal Username As String, ByVal Password As String) As Integer

        Dim con As SqlConnection = New SqlConnection("Data Source=KARANDE\sqlexpress;Initial Catalog=nitink;Integrated Security=True")
        Dim cmdselect As SqlCommand = New SqlCommand()
        cmdselect.CommandType = CommandType.StoredProcedure
        cmdselect.CommandText = "[dbo].[Log_prcLog]"

        cmdselect.Parameters.AddWithValue("@Username", Username)
        cmdselect.Parameters.AddWithValue("@UPassword", Password)
        cmdselect.Parameters.AddWithValue("@OutRes", SqlDbType.Int)



        '   cmdselect.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = Username
        ' cmdselect.Parameters.Add("@UPassword", SqlDbType.VarChar, 50).Value = Password
        'cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4)
        cmdselect.Parameters("@OutRes").Direction = ParameterDirection.Output
        cmdselect.Connection = con
        Dim Results As Integer = 0
        Try
            con.Open()
            cmdselect.ExecuteNonQuery()
            Results = CType(cmdselect.Parameters("@OutRes").Value, Integer)
        Catch ex As SqlException
            lblMessage.Text = ex.Message
        Finally
            cmdselect.Dispose()
            If Not con Is Nothing Then
                con.Close()
            End If
        End Try
        Return Results
    End Function

    Protected Sub btnlogin_Click(sender As Object, e As EventArgs)
        Dim Results As Integer = 0
        If txtUsername.Text <> String.Empty AndAlso txtPassword.Text <> String.Empty Then
            Results = Validate_Login(txtUsername.Text.Trim(), txtPassword.Text.Trim())


            If Results = 1 Then
                lblMessage.Text = "Login is Good, Send the User to another page or enable controls"
            Else
                lblMessage.Text = "Invalid Login"
                lblMessage.ForeColor = System.Drawing.Color.Red

            End If
        Else
            lblMessage.Text = "Please make sure that the username and the password is Correct"
        End If

    End Sub

End Class
Posted
Updated 21-Jun-12 3:23am
v2

1 solution

VB
If Results = 1 Then
lblMessage.Text = "Login is Good, Send the User to another page or enable controls"
Else
lblMessage.Text = "Invalid Login"
lblMessage.ForeColor = System.Drawing.Color.Red

End If
Else
lblMessage.Text = "Please make sure that the username and the password is Correct"
End If



Your are showing only message in the label. Where is the redirection code.(default.aspx ) and check what value you are getting on Results variable.
 
Share this answer
 
Comments
Sandeep Mewara 21-Jun-12 9:58am    
My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900