checking name in database

Posted by Suneel161 under Regular Expressions on 3/20/2010 | Views : 1131 | Status : [Member] | Replies : 2
hii

i have textbox(statename) in my form.how to check for the availability of a statename in sql database using asp.net 3.5 c#.how to solve this problrm.




Responses

Posted by: Vuyiswamb on: 3/20/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
This is simple ,

1) Write a Stored Procedure that will count the number of records in the database that match that statename and in you code before you save to the db, do a check if the records greater than 0 then it exists and display the appropriate message. Understand ?

Thank you for posting at Dotnetfunda
[Administrator]

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 3/23/2010 [Member] Starter

Up
0
Down
Hi
SqlCommand cmd=new SqlCommand("select statename from tablename where statename='"+txtstatename.Text+"'",conn);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
lable1.Text="Statename is already existed";
}
else
{
label1.Text="statename not present";
}

Syed Shakeer Hussain

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response