Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 11-Jan-13 21:34pm
Edited 11-Jan-13 22:39pm
v3
Comments
OriginalGriff at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can check using
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.
  Permalink  
v2
Comments
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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...
  Permalink  
Comments
Marcus Kramer at 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)

  Print Answers RSS
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100