Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have one picturebox in my software and i want to change picture of that for every time i click on search movie. i want to show me the picture of the movie that i searched.
how to do that ?
Posted
Comments
Mukesh Pr@sad 23-Jul-15 1:44am    
According to the search keyword bind the picture box with the related image.
HKHerron 23-Jul-15 9:47am    
Please show us your code.
brandon1999 23-Jul-15 11:19am    
this is my code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Film
{
public partial class MovieLib : Form
{
string SqlStr;
SqlCommand SqlCmd;
SqlDataAdapter SqlDa;
SqlDataReader SqlDr;

public MovieLib()
{
InitializeComponent();
}

public void Clear()
{
TxtName.Text = "";
TxtDirector.Text = "";
TxtYear.Text = "";
TxtType.Text = "";
}

private static SqlConnection CreateConnection()
{
return new SqlConnection("Data Source=(local);Initial Catalog=Movies;Integrated Security=True");
}

private void BtnAdd_Click(object sender, EventArgs e)
{
using (SqlConnection connection = CreateConnection())
using (SqlCommand command = new SqlCommand("Insert into Movies([Name], [Director], [Year], [Type]) VALUES (@Name, @Director, @Year, @Type)", connection))
{
command.Parameters.AddWithValue("@Name", TxtName.Text);
command.Parameters.AddWithValue("@Director", TxtDirector.Text);
command.Parameters.AddWithValue("@Year", TxtYear.Text);
command.Parameters.AddWithValue("@Type", TxtType.Text);

try
{
connection.Open();
command.ExecuteNonQuery();

MessageBox.Show("Inserted successfully.");
Clear();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
// TODO: Log the error somewhere
}
}
}

private void BtnEdit_Click(object sender, EventArgs e)
{
using (SqlConnection connection = CreateConnection())
using (SqlCommand command = new SqlCommand("UPDATE Movies SET Name = @Name, Director = @Director, Year = @Year, Type = @Type WHERE Id_Movies = @id", connection))
{
command.Parameters.AddWithValue("@Name", TxtName.Text);
command.Parameters.AddWithValue("@Director", TxtDirector.Text);
command.Parameters.AddWithValue("@Year", TxtYear.Text);
command.Parameters.AddWithValue("@Type", TxtType.Text);
command.Parameters.AddWithValue("@Id", TxtId.Text);

try
{
connection.Open();
command.ExecuteNonQuery();

MessageBox.Show("Edited successfully.");
Clear();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
// TODO: Log the error somewhere
}
}
}

private void TxtSearch_Click(object sender, EventArgs e)
{

using (SqlConnection connection = CreateConnection())
using (SqlCommand command = new SqlCommand("SELECT Name, Director, Year, Type FROM Movies WHERE Id_Movies = @id", connection))
{
command.Parameters.AddWithValue("@Id", TxtId.Text);

try
{
connection.Open();

using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
if (!reader.Read())
{
MessageBox.Show("Movie not found.");
}
else
{
TxtName.Text = (string)reader["Name"];
TxtDirector.Text = (string)reader["Director"];
TxtYear.Tex

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