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
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shweta LodhaPosted Feb 7, 2014, 4:09 PM
{
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();
}
louis TundePosted Feb 7, 2014, 4:03 PM
Shweta LodhaPosted Feb 7, 2014, 3:46 PM
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');