HI All,
i am inserting , say name to sqlite, than showing it on tableview开发者_JS百科.
But i want say restrict user to insert duplicate name.
for first time data gets inserted perfectly, but when i insert it on second time, it again get inserted, thats what i want to prevent.
HOw can i check if the value 'name' already exist in sqlite and show alert to tell user that this value already exist.
edited
i have an array abc , having few values., values in array i am adding from another view, now say if abc contains value "a1", now if i again inserting "a1", it should not except "a1", in a way how i can restrict an array to add duplicate value.
regards
Use unique constraint in your SQL database. Here's a link with some basics on it. Here's some specifics on how to create table with unique contraints with SQLite.
To alert users, just capture the error message from your SQL query and then output as needed.
Edited (for new question):
Easiest way is to parse through the array and do duplicate checks. There's logic out there for faster searching but if you have a small array, then all you really need is a for loop that iterates through each array element and checks that the new value you are adding is not already there.
精彩评论