I want to store it in a table called movies, where it has a foreign key, gen_id.
In the table generos I have populated with 4 genres.
Now in C # I have the SQL command step by string but it tells me that there is an error in the foreign key gen_id.
public void Registrar()
{
try
{
SqlConnection conexion = new SqlConnection("server=EMILIANO-PC ; database=VideoClub ; integrated security = true");
conexion.Open();
string cadena = "insert into pelicula(nombre_pelicula,web_pelicula,descripcion,anio,idgenero) values ('" + txtnombre.Text.Trim() + "','" + txtweb.Text.Trim() + "' , '" + txtdescripcion.Text.Trim() + "', '" + txtanio.Text + " ', '" + comboBox1.SelectedValue + " ')";
SqlCommand comando = new SqlCommand(cadena, conexion);
comando.ExecuteNonQuery();
MessageBox.Show("Los datos se guardaron correctamente");
conexion.Close();
}
catch (Exception exception)
{
MessageBox.Show(exception.ToString());
}
}
now the error that comes to me is the following:
Add .ToString to the SelectValue