I'm having trouble saving information in the dropdown by btn-save I have a form of registration of real estate being that the information inserted in the dropdown occurs only when I save in another page (that would be) I can not save in the database, what could it be? follow the code ASPX.CS
protected void btnSalvarImovel_Click(object sender, EventArgs e)
{
try
{
Imovel a = new Imovel();
Convert.ToInt32(ddlCidade.SelectedItem.Value);
Convert.ToInt32(ddlLocalizacao.SelectedItem.Value);
Convert.ToInt32(ddlOperacao.SelectedItem.Value);
Convert.ToInt32(ddlTipoImovel.SelectedItem.Value);
a.Titulo = txtTitulo.Text;
a.QntQuarto = Convert.ToInt32(txtQtdQuartos.Text);
a.Obs = txtObservacao.Text;
a.Valor = Convert.ToDouble(txtValor.Text);
ImovelDao d = new ImovelDao();
d.SalvarImovel(a);
txtObservacao.Text = string.Empty;
txtQtdQuartos.Text = string.Empty;
txtTitulo.Text = string.Empty;
txtValor.Text = string.Empty;
}
catch (Exception)
{
throw;
}
}
DAL
public void SalvarImovel(Imovel i)
{
try
{
var command = new SqlCommand("INSERT INTO Imovel(IdCidade,IdLocal,Idtipo,IdOperacao,Titulo,Obs,QntQuarto,Valor) VALUES(@IdCidade,@IdLocal,@Idtipo,@IdOperacao,@Titulo,@Obs,@QntQuarto,@Valor)", Conexao.connection);
Conexao.connection.Open();
command.Parameters.AddWithValue("@IdCidade", i.IdCidade);
command.Parameters.AddWithValue("@IdLocal", i.IdLocal);
command.Parameters.AddWithValue("@IdTipo", i.IdTipo);
command.Parameters.AddWithValue("@IdOperacao", i.IdOperacao);
command.Parameters.AddWithValue("@Titulo", i.Titulo);
command.Parameters.AddWithValue("@Obs", i.Obs);
command.Parameters.AddWithValue("@QntQuarto", i.QntQuarto);
command.Parameters.AddWithValue("@Valor", i.Valor);
command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception("Erro ao salvar o Imóvel, atualize a página e tente novamente, se persistir o erro, contate o suporte" + ex.Message);
}
finally
{
Conexao.connection.Close();
}
}
}