0
I was wondering if there’s any way I could save two different pieces of information into the same attribute in the database. Like I have two textbox, one Cpf and one cnpj. I wanted to save Cpf and cnpj together. Only I created two textbox, one for each one.
Model code
public int idClientefisico { get; set; }
public string nome { get; set; }
public string rg { get; set; }
public string cpf { get; set; }
public string email { get; set; }
public string endereco { get; set; }
public string nr { get; set; }
public string cep { get; set; }
public string estado { get; set; }
public string telefone { get; set; }
public string cidade { get; set; }
public void Insert(Model.cliente_fisico clientefisico)
{
SqlConnection conexao = new SqlConnection(strCon);
string sql = @"Insert into cliente_fisico values
(@nome,@rg,@cpf,@email,@endereco,@nr,@cep,@estado,@telefone,@cidade)";
SqlCommand cmd = new SqlCommand(sql, conexao);
cmd.Parameters.AddWithValue("@nome", clientefisico.nome);
cmd.Parameters.AddWithValue("@rg", clientefisico.rg);
cmd.Parameters.AddWithValue("@cpf", clientefisico.cpf);
cmd.Parameters.AddWithValue("@email", clientefisico.email);
cmd.Parameters.AddWithValue("@endereco", clientefisico.endereco);
cmd.Parameters.AddWithValue("@nr", clientefisico.nr);
cmd.Parameters.AddWithValue("@cep", clientefisico.cep);
cmd.Parameters.AddWithValue("@estado", clientefisico.estado);
cmd.Parameters.AddWithValue("@telefone", clientefisico.telefone);
cmd.Parameters.AddWithValue("@cidade", clientefisico.cidade);
conexao.Open();
try
{
cmd.ExecuteNonQuery();
}
catch
{
Console.WriteLine("Deu erro na inserção de Cliente do tipo fisico ... ");
}
finally
{
conexao.Close();
}
}
I couldn’t understand anything, really. You can [Dit] your publication and try to make it clearer.
– Jéf Bueno
became clearer?
– TMBruhTH
There’s a way to do that. That’s what I wanted to know?
– Jéf Bueno
Yes, I would like to know the way it is because then I would create another table to store only two different types of data.
– TMBruhTH