In my webpage there is a text box in which user enters a name and then clicks the ok button to insert the value in the database. Now my task is to write validation so that the user doesnot enter the name which already exists in the database.It should throw the error saying that name already exists.I tryed the code in msdn for this purpose for some reason it does not work. Any help with the code is greatly appreciated.Bye
Assume the string in your textbox is "name1", you open a DBConnection and DBCommand, set the command text to stuffs like "Select * From [YourDB] Where name=name1", ExecuteNonQuery() and see its return value, which is a int indicating the affected rows.
If it returns 0, insert; If above zreo, throw your exception~
Thanks gordan for ur reply,but my problem i have to validate through dataset which i am using insert the data i cant open an other connection to database that my problem. Iam creating a dataview and trying to loop through table and compare each value againist that column but unable to that.
Any help in this way is greatly useful to me.
No comments:
Post a Comment