Results 1 to 2 of 2

Thread: checking the value of the textbox against the data in the table?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    Question checking the value of the textbox against the data in the table?

    I am new for C#. i am developing web application using C#,asp.net and my database sql server 2005.
    my table has for column:
    firstname,lastname,username ,email
    username and email must be unique with in the table.
    now
    i have a registration form:
    firstname:
    lastname:
    username:
    email:



    now i want to check username and email if they already registered... so that if username or and email are already registered, i want to show a message on label username or and email are taken, try with other username or and email.

    notice.. i know how to add/insert data into my table without checking the value on table, but i could not how can i check the value of the textbox against the value on my table .
    your help please

  2. #2
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: checking the value of the textbox against the data in the table?

    its pretty simple. you need to query the table where the username matches. if it does, then return the ID of that or some value to indicate that it exists.

    Example:

    Code:
    using (SqlCommand command = new SqlCommand("SELECT [ID] FROM Users WHERE EmailAddress = @p1", new SqlCommand(connectionStringHere))
    {
       SqlParameter p1 = new SqlParameter("@p1", emailAddressHere);
       command.Parameters.Add(p1);
       command.Connection.Open();
     
       if (reader.Read() && reader.HasRows)
       {
         // a records already exists  
       }
       command.Connection.Close();
    }

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width