Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Dynamic Websites w/ Web Matrix
This is the forum to discuss the Wrox book Beginning Dynamic Websites: with ASP.NET Web Matrix by Dave Sussman, James Greenwood, Alex Homer, Colt Kwong, John M. West; ISBN: 9780764543746
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Dynamic Websites w/ Web Matrix 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 July 27th, 2004, 11:23 AM
Authorized User
 
Join Date: Jun 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do i check if user name is exist in my DB

i'm newbi to all this, but i managed to create a lofin page in webmatrix usin ASP and a config file and default page but when i create the registeration page i encountrer a problem if i try to use an existing use name
how can i i go about creating a msg to show that USerID already exist BUT HOW CAN I SEARCH FOR IT FIRST..I'M using VB.NET it might sound silly but i,m really stuck on that one
help pls

 
Old July 27th, 2004, 11:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Are you storing the user id's/passwords in the config file or in the database?

Brian
 
Old July 28th, 2004, 04:04 AM
Authorized User
 
Join Date: Jun 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx @bmains
i'm storing it in database file
in a form of table coulmn for User id the other for passi used the insertmethod by the ASP code genrator......i couldn't create SQL query to look in table first...by the way if i use any UserID i created ASP will genrate an error saying primry key 1_51_ cannot be dublicated
i appreciate any help thanx

 
Old July 28th, 2004, 06:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

So you have some code created... could you post that relevant code? There seems to be a lot going on and I can't tell what your problem is without seing it.

Brian
 
Old July 28th, 2004, 07:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Function DBAuthenticate(ByVal strUsername As String, ByVal strPassword As String) As Integer
        Dim bResult As Boolean = False
        Dim objConn As New OleDbConnection(ConfigurationSettings.AppSettings( "myDB"))
        Dim strSQL As String
        Dim strGoodPassword As String
        Dim objCommand As New OleDbCommand

        objCommand.Connection = objConn
        strSQL = String.Format("SELECT p_w FROM myDB WHERE (email='{0}');", strUsername)
        objCommand.CommandText = strSQL
        objCommand.CommandType = CommandType.Text

        objConn.Open()
        strGoodPassword = CType(objCommand.ExecuteScalar, String)
        objConn.Close()

        If Not strGoodPassword Is Nothing Then
            If strGoodPassword = strPassword Then
                bResult = True
            Else
                lblMessage.Text = "Invalid Login!"
                lblMessage.Text &= " If you are not a member please click the above link to register."
            End If
        Else
            lblMessage.Text = "Invalid Login!"
            lblMessage.Text &= " If you are not a member please click the above link to register."
        End If

        Return bResult
    End Function

This function takes the username and password passed to it from the "Button1_Click" Sub and checks to see if they are valid.

 
Old July 28th, 2004, 02:27 PM
Authorized User
 
Join Date: Jun 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here is the code i managed to generate usin INSERT METHOD i hope thta going to help u help me
I'M VERY GRATEFULL FOR THE HELP... other forum took the miky because i couldn't create an SQL query
here it is


Sub btnRegister_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
MyInsertmethod(txtUserID.text, txtPassword.text)
end if
End Sub
    Function MyInsertMethod(ByVal userId As String, ByVal userpassword As String) As Integer
        Dim connectionString As String = "server='ABBAS\NetSDK'; trusted_connection=true; Database='login'"
        Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionStri ng)

        Dim queryString As String = "INSERT INTO [Users] ([UserId], [Userpassword]) VALUES (@UserId, @Userpassword)"
        Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

        sqlCommand.Parameters.Add("@UserId", System.Data.SqlDbType.Char).Value = userId
        sqlCommand.Parameters.Add("@Userpassword", System.Data.SqlDbType.Char).Value = userpassword

        Dim rowsAffected As Integer = 0
        sqlConnection.Open
        Try
            rowsAffected = sqlCommand.ExecuteNonQuery
        Finally
            sqlConnection.Close
        End Try

        Return rowsAffected
    End Function

    Sub txtPassword_TextChanged(sender As Object, e As EventArgs)

End Sub


 
Old July 28th, 2004, 03:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Are you trying to create a login page or a registration page?

 
Old July 28th, 2004, 07:16 PM
Authorized User
 
Join Date: Jun 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@stue9820
what i did is i created the login page but in the same time i created registeration page in a form of User ID & password so if a new user want to register i would like to check if this new user choose a userID already there if sh/he does i need to create a msg to say user already exists
thanx once more for the education & time

 
Old July 28th, 2004, 08:24 PM
Authorized User
 
Join Date: Jun 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi guys i know i troubled u all but here what i get if i'm trying with existing user name:

Violation of PRIMARY KEY constraint 'PK_Info_1__51'. Cannot insert duplicate key in object ('Info' is My DB name). The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_Info_1__51'. Cannot insert duplicate key in object 'Info'. The statement has been terminated.


 
Old July 28th, 2004, 08:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Yeah, that's it's inserting the name. Are you trying to login with that name, or register that name? Seems like something is crossing over here.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Check if directory exist ArnArn XSLT 3 November 23rd, 2008 03:44 PM
values dont show up on ASP page but exist in DB msoul Classic ASP Basics 2 September 3rd, 2008 02:03 PM
How can I check whether a user is logged in or out rittwick PHP Databases 1 August 19th, 2007 04:47 PM
check for image field exist goldenstate ASP.NET 2.0 Basics 2 May 22nd, 2007 12:36 PM
How do I check a db before inserting a record? Lucy SQL Server ASP 3 April 25th, 2005 10:47 PM





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