Try something like this. I typed this off the top of my head so it may need some tweaking.
SqlConnection conn = null;
Sqlmmand cmd = new SqlCommand(conn);
string ddlItem = "";
if (DDLItem.SelectedItem != null)
{
ddlItem = (Cast to whatever type it is)DDLItem.SelectedItem.Text;
}
if (ddlItem != "")
{
try
{
conn = new SqlConnection(connectionString);
cmd = new SqlCommand(conn);
cmd.CommandType = CommandType.Text;
foreach (ListItem LBox4Item in ListBox4.Items)
{
ListBox5.Items.Add(LBox4Item);
int value = LBox4Item.ToString();
string query = string.Format("update Product set BalanceOnStock='{0}' where ProHead='{1}'", value.ToString(), ddlItem);
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
}
catch(Exception ex)
{
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}