ado.net - dataset doesn't update anything in C# -


i have written procedure in ms-sql

alter proc [dbo].[gravacliente] select     idcliente, nome, endere, tel_empresa, celular,     uf, cep, email, contato, referencia, obs, nasc,     cpf, cnpj, iest     tbcliente 

and code, too

dataset grava = new dataset(); sqldataadapter da2 = new sqldataadapter(); sqlcommandbuilder constru6 = new sqlcommandbuilder(da2); sqlcommand llena8 = new sqlcommand("gravacliente", conec1); llena8.commandtype = commandtype.storedprocedure; da2.selectcommand = llena8; da2.fill(grava, "tbcliente"); datarow dr = grava.tables["tbcliente"].newrow(); dr.beginedit(); dr["nome"] = txtnome.text; dr["endere"] = txendere.text;  dr.endedit(); da2.update(grava.tables["tbcliente"]); label9.text = txtnome.text; 

conec1 working above code doesn't update anything. error?

first, must add row table.

datarow dr = grava.tables["tbcliente"].newrow();  dr["nome"] = txtnome.text; dr["endere"] = txendere.text;   grava.tables["tbcliente"].addrow(dr); 

also, afaik, sqlcommandbuilder won't work stored proc. must either provide update command adapter or use text-based select command:

sqlcommand llena8 = new sqlcommand("select idcliente, nome, endere, tel_empresa, celular, uf, cep, email, contato, referencia, obs, nasc, cpf, cnpj, iest tbcliente", conec1); 

of course, need call before doing update:

constru6.getupdatecommand(); 

my recommendation don't use sqlcommandbuilder @ because of overhead costs. if insist on using i'd suggest read documentation.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -