0

So my group and i have been working on a ASP.net website for a tech prep showcase. We currently have connected the MS Sql Database that comes with Visual Web Developer. We are currently having a problem gathering data from the SQL Database and seeing if it is equivalent to the users input. We have attempted this for last 3 days and still have difficulty with it. We are using VB for the back side programing.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration

    Protected Sub Login1_Authenticate(ByVal sender As Object, _
                                      ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) _
                                      Handles Login1.Authenticate
        Dim username As String
        Dim pwd As String
        Dim pName As String

        username = Login1.UserName
        pwd = Login1.Password



            pName = ""

        Dim conn1 As New SqlConnection()
        conn1.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

        conn1.Open()




        Dim sqlUserName As String
        sqlUserName = "Select UserName, password FROM LogIn"
        sqlUserName &= " WHERE (UserName = @UserName"
        sqlUserName &= " AND password = @Password)"

        Dim com As New SqlCommand(sqlUserName, conn1)
        com.Parameters.AddWithValue("@UserName", username)
        com.Parameters.AddWithValue("@Password", pwd)


        If username = sqlUserName Then
            Response.Redirect("index.asp")

        End If






        conn1.Close()

    End Sub

Edited by bryanhiehle: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by SolutionExpert
0

please replace the following code

If username = sqlUserName Then 
Response.Redirect("index.asp") 
End If

with

Dim strUser as string =""
strUser = com.ExecuteScalar()

If username = strUser Then 
Response.Redirect("index.asp") 
End If

Thats all ... Let me know if it works.

Thanks
VJ

Edited by Ezzaral: Added code tags. Please use them to format all code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.