Save multiple photos in the SQL database in the same ID

1

I'm having trouble saving multiple photos in a single id This is the cs of the page that makes the registration

protected void btnSalvarImovel_Click(object sender, EventArgs e)
    {
        try
        {
            var cmd = new SqlCommand("INSERT INTO Imovel(IdCidade,IdLocal,Idtipo,IdOperacao,Titulo,Obs,QntQuarto,Valor,Foto)" +
            "values(@IdCidade,@IdLocal,@Idtipo,@IdOperacao,@Titulo,@Obs,@QntQuarto,@Valor,@Foto)", con);
            cmd.Parameters.AddWithValue("@IdCidade", ddlCidade.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@IdLocal", ddlLocalizacao.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@IdTipo", ddlTipoImovel.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@IdOperacao", ddlOperacao.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@Titulo", txtTitulo.Text);
            cmd.Parameters.AddWithValue("@Obs", txtObservacao.Text);
            cmd.Parameters.AddWithValue("@QntQuarto", txtQtdQuartos.Text);
            cmd.Parameters.AddWithValue("@Valor", txtValor.Text);
                foreach (var file in fuFotos.PostedFiles)
                {
                    string filename = Path.GetFileName(file.FileName);
                    file.SaveAs(Server.MapPath("~/Imovel/" + filename));
                    cmd.Parameters.AddWithValue("@Foto", file);

                }
                con.Open();
                cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {

            throw new Exception("Erro ao salvar a Imóvel, atualize a página e tente novamente, se persistir o erro, contate o suporte" + ex.Message);
        }
        finally
        {
            con.Close();
        }
    }

In case FOREACH would be the loop to store several photos

and gives the following error:

I'dlikeyoutostay-+onthebenchWhatcanIdo?anytips?

    
asked by anonymous 05.10.2016 / 02:25

0 answers