hi,
there .i am coming up with a login page authentication, however i am getting this error that says 'Type SQl.Data.SqlClient.SqlDataReadercon1 is not defined '

[B]Dim reader As System.Data.SqlClient.SqlDataReadercon1 [/B]

<%@ Page Language="VB" MasterPageFile="~/CouierMasterPage.master" Title="Untitled Page" %>
<%@ Import Namespace="System.Data.OleDB" %>
<%@ Import Namespace="System.ComponentModel" %>
<%@ import namespace="system.web.security" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.SqlClient.SqlException" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Web" %>




<script runat="server">
    Sub OnLoginError(ByVal sender As Object, ByVal e As EventArgs)
        Login1.PasswordRecoveryText = "Forgot your password?"
    End Sub
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Session("Check") <> Nothing) And Convert.ToBoolean(Session("Check")) Then

            If (User.Identity.IsAuthenticated) Then

                Response.Redirect("f_main.aspx")
            End If
        End If
    End Sub



    

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        Dim blnResult As Boolean = False

        blnResult = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password)

        If (blnResult) Then

            Session("Check") = True

            e.Authenticated = True

        Else

            Session("Check") = False

            e.Authenticated = False

        End If

    End Sub
    
    
    Protected Function SiteSpecificAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean

        Dim log_statement As String = "SELECT * FROM [user] where username='" & UserName & "' and password='" & Password & "'"

        Dim con2 As System.Data.SqlClient.SqlCommand
        Dim con1 As System.Data.SqlClient.SqlConnection

        Dim reader As System.Data.SqlClient.SqlDataReadercon1 = New System.Data.SqlClient.SqlConnection(SqlDataSource1.ConnectionString)
        con1.Open()

        con2 = New System.Data.SqlClient.SqlCommand(log_statement, con1)
        reader = con2.ExecuteReader()

        If reader.Read Then

            Return True

        Else

            Return False

        End If

    End Function
    
    


    Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    
   
     
    </asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CourierSystemConnectionString %>" 
        
        InsertCommand="Select_Login"
            InsertCommandType="StoredProcedure" 
        SelectCommand="SELECT UserID, Password FROM StaffRegis_Table where ((UserID=@UserID) AND (Password=@Password))">
        
        <SelectParameters>
            <asp:CookieParameter CookieName="UserID" DefaultValue="User ID" 
                Name="USerID" />
            <asp:CookieParameter CookieName="Password" DefaultValue="Password" 
                Name="Password" />
        </SelectParameters>
        
        <InsertParameters>
                
                <asp:Parameter Name="UserID" Type="String" />
                <asp:Parameter Name="password" Type="String" />
            </InsertParameters>
    
    </asp:SqlDataSource>
    <asp:Login ID="Login1" runat="server" CreateUserUrl="~/PasswordRecover.aspx" CreateUserText="Forgot your password?"
      Height="58px" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" OnAuthenticate="Login1_Authenticate">
        <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <LayoutTemplate>
            <table border="0" cellpadding="1" cellspacing="0" style="border-collapse: collapse;
                height: 150px; width: 244px;">
                <tr>
                    <td>
                        <table border="0" cellpadding="0" style="height: 58px">
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #6b696b">
                                    Log In</td>
                                <td align="center" colspan="1" style="font-weight: bold; color: white; background-color: #6b696b">
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                                        ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Password" runat="server" TextMode="Password" Height="22px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                        ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
                                </td>
                                <td colspan="1">
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color: red">
                                    <br />
                                    <asp:LinkButton ID="LbTNPassword" runat="server" 
                                        PostBackUrl="~/PasswordRecover.aspx">Forgot your password?</asp:LinkButton>
                                    <br />
                                    <br />
                                    <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/StaffRegis.aspx">Create 
                                    an account</asp:LinkButton>
                                    &nbsp;<br />
                                    <br />
                                </td>
                                <td align="center" colspan="1" style="color: red">
                                    &nbsp;</td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <br />
                                    <br />
                                    <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" 
                                        ValidationGroup="Login1" PostBackUrl="~/Transactions.aspx" 
                                        onclick="LoginButton_Click" />
                                </td>
                                <td align="right" colspan="1">
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
    </asp:Login>

    </asp:Content>

Dani AI

Generated

The compile error stems from a malformed declaration and mixed-up objects: the SqlDataReader type name was accidentally concatenated with a variable name, and a SqlConnection was being created/used in the place of the reader. is correct that the reader declaration must be fixed, but the real fix is to keep connection, command and reader as separate, properly-instantiated objects and to use a safe pattern that disposes them reliably.

A clearer, safer pattern (Using blocks + parameterized SQL) keeps the types straight and avoids the common mistakes seen in the thread:

' VB.NET pattern: Using blocks, parameters, ExecuteScalar for existence check
Protected Function SiteSpecificAuthenticationMethod(userName As String, password As String) As Boolean
    Dim sql As String = "SELECT COUNT(1) FROM [user] WHERE username=@u AND password=@p"
    Using cn As New SqlConnection("<connection string here>")
        Using cmd As New SqlCommand(sql, cn)
            cmd.Parameters.AddWithValue("@u", userName)
            cmd.Parameters.AddWithValue("@p", password) ' replace with hashed comparison in production
            cn.Open()
            Dim matches As Integer = Convert.ToInt32(cmd.ExecuteScalar())
            Return (matches > 0)
        End Using
    End Using
End Function

Practical improvements and cautions: never concatenate user input into SQL (use parameters), don’t store plaintext passwords — use salted hashes or the built-in membership/identity systems, and avoid wiring a Button’s PostBackUrl that can skip proper authentication flow (let the Login control or FormsAuthentication handle redirects after setting e.Authenticated). Also remove incorrect or unnecessary Imports and ensure the SqlDataSource/connection string used is the same one actually available at runtime.

Quick troubleshooting checklist: fix the declaration, instantiate/open the SqlConnection variable, run the query in SQL Management Studio to verify results, set breakpoints to confirm connection state, and rebuild. These steps will resolve the compile error and make the login flow safer and more reliable for .

what is?:

Dim reader As System.Data.SqlClient.SqlDataReadercon1

the con1 is a mistake remoe it and use it like this:
Dim reader As System.Data.SqlClient.SqlDataReader

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.