Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 22nd, 2004, 12:45 AM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Form allows multiple user to register same userid

I used this page to register user for my web page. But the form allows users to register same userid. Does not give any error message.

<%@ Page Language="VB" %>
<script runat="server">

    Function insertUser(ByVal userID As String, ByVal firstname As String, ByVal lastname As String, ByVal address As String, ByVal email As String, ByVal password As String) As Integer
            Dim connectionString As String = "server=servername; database=databasename; uid=userid; pwd=password;"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionStri ng)

            Dim queryString As String = "INSERT INTO [userTable] ([userID], [firstname], [lastname], [address]"& _
    ", [email], [password]) VALUES (@userID, @firstname, @lastname, @address"& _
    ", @email, @password)"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            Dim dbParam_userID As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_userID.ParameterName = "@userID"
            dbParam_userID.Value = userID
            dbParam_userID.DbType = System.Data.DbType.StringFixedLength
            dbCommand.Parameters.Add(dbParam_userID)
            Dim dbParam_userFirstName As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_userFirstName.ParameterName = "@firstname"
            dbParam_userFirstName.Value = firstname
            dbParam_userFirstName.DbType = System.Data.DbType.StringFixedLength
            dbCommand.Parameters.Add(dbParam_userFirstName)
            Dim dbParam_userLastName As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_userLastName.ParameterName = "@lastname"
            dbParam_userLastName.Value = lastname
            dbParam_userLastName.DbType = System.Data.DbType.StringFixedLength
            dbCommand.Parameters.Add(dbParam_userLastName)
            Dim dbParam_userAddress As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_userAddress.ParameterName = "@address"
            dbParam_userAddress.Value = address
            dbParam_userAddress.DbType = System.Data.DbType.StringFixedLength
            dbCommand.Parameters.Add(dbParam_userAddress)
            Dim dbParam_userEmail As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_userEmail.ParameterName = "@email"
            dbParam_userEmail.Value = email
            dbParam_userEmail.DbType = System.Data.DbType.StringFixedLength
            dbCommand.Parameters.Add(dbParam_userEmail)
            Dim dbParam_userPass As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_userPass.ParameterName = "@password"
            dbParam_userPass.Value = password
            dbParam_userPass.DbType = System.Data.DbType.StringFixedLength
            dbCommand.Parameters.Add(dbParam_userPass)

            Dim rowsAffected As Integer = 0
            dbConnection.Open
            Try
                rowsAffected = dbCommand.ExecuteNonQuery
            Catch ex As Exception
                Message.Text = "The User ID already Exists!!!"
            Finally
                dbConnection.Close
            End Try

            Return rowsAffected
        End Function

    Sub submitButton_Click(sender As Object, e As EventArgs)
    If Page.IsValid Then
    If InsertUser(txtUserID.Text, txtUserFirstName.Text, txtUserLastName.Text, txtUserAddr.Text, txtUserEmail.Text, txtUserPass.Text) > 0
         FormsAuthentication.SetAuthCookie(txtUserFirstName .Text, false)
         Response.Redirect("Login.aspx")
    End If
    End If
    End Sub

    Sub resetButton_Click(sender As Object, e As EventArgs)
      txtUserID.Text = ""
      txtUserFirstName.Text =""
      txtUserLastName.Text =""
      txtUserAddr.Text =""
      txtUserEmail.Text = ""
      txtUserPass.Text = ""
      Message.Text = ""

    End Sub

    Sub Button1_Click(sender As Object, e As EventArgs)
      Response.Redirect("default.aspx")
    End Sub

</script>
<html>
<head>
    <title>studentBooks Registration Page</title>
</head>
<body >
    <form runat="server">
        <p align="center">
            <strong>New User Registration </strong>
        </p>
        <p align="center">
            Please fill in all the required information
        </p>
        <p align="center">
        </p>
        <p>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="Label1" runat="server" forecolor="DarkBlue">First
            Name</asp:Label>&nbsp;&nbsp;&nbsp; &nbsp;<asp:TextBox id="txtUserFirstName" runat="server" MaxLength="20" Width="144px"></asp:TextBox>
            <asp:RequiredFieldValidator id="firstNameValidator" runat="server" ErrorMessage="* Field Required" ControlToValidate="txtUserFirstName"></asp:RequiredFieldValidator>
        </p>
        <p>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="Label2" runat="server" forecolor="DarkBlue">Last
            Name</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="txtUserLastName" runat="server" MaxLength="20" Width="144px"></asp:TextBox>
            &nbsp;<asp:RequiredFieldValidator id="lastNameValidator" runat="server" ErrorMessage="* Field Required" ControlToValidate="txtUserLastName"></asp:RequiredFieldValidator>
        </p>
        <p>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="Label3" runat="server" forecolor="DarkBlue">Address</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;
            <asp:TextBox id="txtUserAddr" runat="server" MaxLength="30" Width="241px"></asp:TextBox>
            &nbsp;<asp:RequiredFieldValidator id="addressValidator" runat="server" ErrorMessage="* Field Required" ControlToValidate="txtUserAddr"></asp:RequiredFieldValidator>
        </p>
        <p>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="Label4" runat="server" forecolor="DarkBlue">Email</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="txtUserEmail" runat="server" MaxLength="20" Width="144px"></asp:TextBox>
            &nbsp;<asp:RequiredFieldValidator id="emailValidator" runat="server" ErrorMessage="* Field Required" ControlToValidate="txtUserEmail"></asp:RequiredFieldValidator>
        </p>
        <p>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;
            &nbsp;&nbsp; <asp:Label id="Label5" runat="server" forecolor="DarkBlue">User ID</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;<asp:TextBox id="txtUserID" runat="server" MaxLength="10" Width="144px"></asp:TextBox>
            &nbsp;
            <asp:RequiredFieldValidator id="IDValidator" runat="server" ErrorMessage="* Field Required" ControlToValidate="txtUserID"></asp:RequiredFieldValidator>
        </p>
        <p>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="Label6" runat="server" forecolor="DarkBlue">Password</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp :TextBox id="txtUserPass" runat="server" MaxLength="15" Width="144px" TextMode="Password"></asp:TextBox>
            &nbsp;&nbsp;<asp:RequiredFieldValidator id="passValidator" runat="server" ErrorMessage="* Field Required" ControlToValidate="txtUserPass"></asp:RequiredFieldValidator>
        </p>
        <p>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="Label7" runat="server" forecolor="DarkBlue">Re
            enter Password</asp:Label>&nbsp;&nbsp; &nbsp;
            <asp:TextBox id="txtRePass" runat="server" MaxLength="15" Width="144px" TextMode="Password"></asp:TextBox>
            &nbsp;
            <asp:CompareValidator id="ComparePass" runat="server" ErrorMessage="* Passwords MUST match" ControlToValidate="txtRePass" ControlToCompare="txtUserPass"></asp:CompareValidator>
        </p>
        <p>
        </p>
        <p align="center">
            <asp:Button id="submitButton" onclick="submitButton_Click" runat="server" Text="Submit"></asp:Button>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button id="resetButton" onclick="resetButton_Click" runat="server" Text="Clear" CausesValidation="False"></asp:Button>
        </p>
        <p align="center">
            <asp:Label id="Message" runat="server"></asp:Label>
        </p>
        <p align="center">
            <asp:HyperLink id="HyperLink1" runat="server" Font-Names="Times New Roman" Font-Size="Large">
                <a href= 'default.htm'>Back to Home</a>
            </asp:HyperLink>
            &nbsp;
        </p>
    </form>
</body>
</html>


 
Old May 12th, 2004, 10:14 AM
Registered User
 
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is the column userID in table userTable defined as Unique Constraint? If not, the database will not check for any duplicates.

Manish Jadhav







Similar Threads
Thread Thread Starter Forum Replies Last Post
Funky - Login Failed for user 'Domain\UserId' erro jnks2005 ASP.NET 2.0 Basics 5 February 26th, 2007 01:38 PM
Reference UserID of logged in user radiohalo5 BOOK: ASP.NET Website Programming Problem-Design-Solution 2 February 7th, 2006 06:23 PM
Multiple ADO multiple user login Oracle9i jhay0721 Pro VB Databases 1 April 4th, 2005 11:23 AM
register.php: clearing html form fields lamada BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 26th, 2004 01:25 PM
Cash Register web form activexcode Classic ASP Basics 4 October 3rd, 2004 05:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.