Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 'user' table:
fields are:

name
emailid
address
ph.no
password





when i insert new data from textbox,it will check whether name is allready exsist or not .if not exsist then allow to enter name in textbox.
how to do this?

more discription of my problem:
when i enter name in textbox ,it will check weather name is exsist or not.if name exsist, then it will not allow to enter name.
Posted
Updated 11-Jan-13 22:39pm
v3
Comments
OriginalGriff 12-Jan-13 3:37am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.

Hi Friend..

on insertion button click event just do this...

con.Open();
 MySqlCommand cmd = new MySqlCommand("select * from Your_tableUser where name='"+txtboxName.text+"'", con);
        MySqlDataReader dr = cmd.ExecuteReader();
     if (dr.Read())
        {

            Lblmsg.text="Duplicate Entry Found..."; //label that show your error massage 

        }
else
{
Here Do You Insert Code....
}
        con.Close();


I think it will be helpful for you...
 
Share this answer
 
Comments
fjdiewornncalwe 23-Feb-13 11:25am    
No vote from me, but a suggestion. Many of your answers are SQL injection nightmares. So that people learn how to do things properly, ALL answers like this one that build sql queries should use paramaterized queries, not concatenation.
You can check using
C#
string sql = string.format(" select count(*) from table name where name='{0}'", txtname.text);


if it exitst it gives 1 else 0
then u can allow to enter.
 
Share this answer
 
v2
Comments
fjdiewornncalwe 23-Feb-13 11:25am    
No vote from me, but a suggestion. Many of your answers are SQL injection nightmares. So that people learn how to do things properly, ALL answers like this one that build sql queries should use paramaterized queries, not concatenation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900