1
I have a question, how to insert data in a Mysql table, using English, I have the tables below:
I am using the method below to insert:
public void inserirCarteira(float cpf, string codigo, double valor, int quant, double vtotal)
{
try
{
validarInserir(cpf, codigo, valor, quant, vtotal);
// instancia o banco de dados
bancotccEntities1 bco = new bancotccEntities1();
bco.Database.Connection.Open();
// cria um objeto
carteira cart = new carteira();
// popula o objeto
cart.cpf = cpf;
cart.codigo = codigo;
cart.valoracao = valor;
cart.qtdacao = quant;
cart.vtotalacao = vtotal;
// adciona um objeto ao banco
bco.AddTocarteira(cart);
//salva o objeto no banco
bco.SaveChanges();
bco.Database.Connection.Close();
}
catch (Exception e1)
{
throw new Exception(e1.Message.ToString());
}
}
I know I have to use my foreign key but I don’t know what it would be like: Cart.carteira ?
If that’s how I’m going to enter values since the idusuario is the primary key of the user table and is auto increment, so I do not know what will be the value of this field at the time of making an insertion.
Can someone give me an idea of how to do?
I don’t understand. Do you want how to fill in which foreign key to enter? Wallet or User?
– Leonel Sanches da Silva
First I suggest you standardize the table names, decide some pattern can be separated by underscore or uppercase tp v_invested or vInvestido, second Do not need to write idusuario, if it is already in the user table it is evident that the id would refer to the user. Class is better to start with capital letter, it would not be wallet and yes Wallet.
– Felipe Bergamo
Okay thanks! I’ll write it down.
– user9090
Hi Gypsy my idea was to insert data in the Wallet table.
– user9090