Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two forms:
- One is for searching the movie.
- Second one is for adding movie.

What I would like is if a person adds a movie say Fast5 and that movie already exists in the database I want to show an error message box telling that the movie already exist rather then the program crash.

Same thing for the search for a movie if it does not exist in the database an message box telling that there is no such movie.
Posted
Updated 19-Nov-11 10:41am
v2
Comments
Sergey Alexandrovich Kryukov 19-Nov-11 16:40pm    
What is "program crash", exactly? Why do you expect such "crash" even it you try to add existing record? try to query for non-existent object? Did you it? What did you try?
--SA
[no name] 20-Nov-11 0:00am    
What have you tried so far?

1 solution

This smells badly of homework, so no code for you!
However, it isn't complex: you need to add a get "the movie details from the database" function.

1) Connect to the database
2) Set up a SQL command, with the string "SELECT * FROM myTable WHERE movieName=@MN"
3) Use the SQLCommand function Parameters.AddWithValue to add the parameter "@MN" to the command, with the value being the movie name.
4) Use the SQLCommand function ExecuteReader to read records from the DB.
5) If the reader.Read function returns true, there is a movie with than name in the db - you can retrieve the fields.
6) If it doesn't, there is no movie of that name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900