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

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

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.