If you can read the info from the listbox - which your question implies, then it is pretty easy, assuming you have set up the database already. I assume you are using SQL Server?
using (SqlConnection con = new SqlConnection(strConnect))
{
using (SqlCommand com = new SqlCommand("INSERT INTO MyTable (MyColumn1, MyColumn2) VALUES (@VAL1, @VAL2)", con))
{
com.Paramaters.AddWithValue("@VAL1", valueFromListBox1);
com.Paramaters.AddWithValue("@VAL2", valueFromListBox2);
com.ExecuteNonQuery();
}
}
You can get the connection string in the Server Explorer of VS, highlight the database and look at the properties pane.
"It isnt working I created a seperate button and put the code in that sets up the database and the code you gave me but it still isnt working. I've put the code in the question so you can check if its right or not."
The code you have provided does two things: The first section reads from the database and the second writes to it.
Once the first section has read from the database, the information is thrown away, because it all goes out of scope.
The second should work, assuming that "lbxFilms" is a string or similar.
When you say "It doesn't work" what does happen? What happens that shouldn't, or doesn't happen that should? Do you get an error? If so, what?
"The program runs, but when I press the button it doesnt save that data into the database. lbx films is the name of the listbox."
Then I am not surprised: if "lbxFilms" is a whole list box, how do you expect that to be saved to a database?
Get the current user selection, and insert that instead...