Re-registration in the Database

Asked

Viewed 45 times

0

In a database table with the fields Productoid, Description, Unit price and some others. I have a screen that only allows updating the Unit Price field, at the time of re-recording the record in the database as should be the routine to re-record. I did the following routine, but the Description field and others in the table were rewritten without content.

ProdutoRepositorio app = new ProdutoRepositorio();

Produto produto = new Produto();

produto.ProdutoId = codigo;

produto.PrecoUnitatio = decimal.Parse(txtPrecoUnitario.Text);

app.Atualizar(produto);
app.SalvarTodos();

2 answers

1

As you have the product Id, just search for this product within the same update method, until there is already a method for this that is the find:

ProdutoRepositorio app = new ProdutoRepositorio();

//aqui você usa sua logica para buscar o produto
Produto produto = app.produto.find(codigo);

if(produto == null){ } //entra se o produto não existir

produto.PrecoUnitatio = decimal.Parse(txtPrecoUnitario.Text);

app.Atualizar(produto);
app.SalvarTodos();
  • Perfect Cassio, it worked. Thanks. Thank you very much.

  • I’m glad it worked out

  • Gilberto, mark as answer

  • Forgive me ignorance. How to mark as useful answer. I searched but did not find. Thank you.

0

In case you’d have to pull that dice out of the seat and not give it a new one since you’re updating the guy. Dai vc gives a get on the item and changes only what you want to change with the screen input and the rest is what was already in the object returned from the bank.

sort of like this .

var product = app.find(idDoProduct) product.price = valueVindoDaTela ; app.uptadeProduct(product);

  • Okay. I’ll test it. Thank you very much.

  • Hello Gustavo. I consult the record in another method (Reading) and put inside the product var, as your example. How can I get inside the method (Upgrade) to have access to the product var. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.