|
-
Dec 27th, 2011, 02:43 AM
#1
Thread Starter
Addicted Member
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
-
Dec 29th, 2011, 03:50 PM
#2
PowerPoster
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();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|