User exist
i need code so that when i submit to database, if there is a user with the same name it will display user exist on the interface
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Shweta LodhaRank #31 · 39.8K reputationPosted Feb 7, 2014, 10:46 AM EST
You can use IGNORE keyword as shown in below example.
If you will run the below queries, it will insert only 2 records, although I am inserting 3.
CREATE TABLE Table1 ( `username` varchar(30) PRIMARY KEY, `foo` varchar(20) );
INSERT IGNORE INTO Table1 (`username`, `foo`)
VALUES ('s', 'a'), ('h', 'a'), ('s', 'a');
louis TundeRank #6,843 · 255 reputationPosted Feb 7, 2014, 11:03 AM EST
Shweta LodhaRank #31 · 39.8K reputationPosted Feb 7, 2014, 11:09 AM EST
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT IGNORE INTO Table1 (Name,foo) VALUES ('a','s');";
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
}