Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I'm making a Windows form which allows people to select a film from different genres. I've used list boxes to display the list of films and genres. When a user selects a genre, the films from that genre are displayed in another list box. The user selects a film from that list box, then a picture from the film is displayed in a picture box and informtion for the film is displayed in a text box. I have also added a button which the user clicks, once they have selected the film, a message box is displayed with buttons, that asks if they're sure they want to choose this film. If the user clicks "Yes", the picture and info for the film are still displayed on screen as before. If user clicks "No" then the picture and info are cleared from the screen and the user can select another film.

Now I what I want to do is store that film choice in a database. So I can keep a record of the films chosen by the user. The problem is I dont know how to send data into a database based on a selection from a listbox. So for example if I selected "Inception" and confirmed my selection using the message box with buttons, is there a way to store that film choice into the database just by clicking the "Yes" button or would I need to do something different?
Posted

You need to handle the event of the click button.

Once that is handled you can get the current selected item in the listbox by listbox.SelectedItem .

All you then need to do is pass in the relevant values to a Stored Procedure in the database via ADO.net
 
Share this answer
 
Do you mean that you're using a MessageBox with YesNo buttons?

If so, you need to capture the result of the MessageBox and check it against DialogResult.Yes as in:

C#
DialogResult result;
result = MessageBox.Show("Do you want to save this?","Save Inception",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
  //insert into database
 
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