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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 576
1 OriginalGriff 183
2 Tadit Dash 160
3 Sergey Alexandrovich Kryukov 136
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,280
1 OriginalGriff 5,473
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


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