1
I’m having trouble saving information in the dropdown by btn-save I have a property registration form and the information entered in the dropdown occurs only that at the time I save on another page (that would be this) I can not save in the database, what could be? follows 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();
}
}
}
What mistake are you making? Would you be able to put your code
SalvarImovel
– Pablo Tondolo de Vargas
@Pablovargas I edited the question up there, I wanted when enrolling in the dropdown he save in Idcidade what I should do?
– André Felipe Jardim Firmo