0

Hi I am trying to insert the guestpass type name in table guestpasstypes and at a time it will check the database whether the database has already that name or not by using this statement

@"INSERT INTO guestpasstypes(guestPasstype_Name)values('" + tbPassType.Text + "') where not exists (select 'guestPasstype_Name' from guestpasstypes where guestPasstype_Name = '" + tbPassType.Text + "')"

but it accepts the duplicate name also.. and it does not work

I have tried all techniques like WHERE NOT EXSIST types pls help

user682417
  • 1,478
  • 4
  • 25
  • 46
  • Have you tried "INSERT INTO guestpasstypes(guestPasstype_Name) values('" + tbPassType.Text + "') where guestPasstype_Name != '" + your string name + "'" – Matthew Riches Jun 17 '11 at 10:42
  • do you have a unique constraint on the field? – kinakuta Jun 17 '11 at 10:43
  • possible duplicate of [sql table accepting same names again and again database name checking](http://stackoverflow.com/questions/6383618/sql-table-accepting-same-names-again-and-again-database-name-checking) – Mikael Eriksson Jun 17 '11 at 10:44

1 Answers1

1

Use a unique constraint. Check out this previous question: How do I specify unique constraint for multiple columns in MySQL?

Community
  • 1
  • 1
Chuck Bergeron
  • 2,037
  • 2
  • 15
  • 18