471,348 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Insert and update don't work



Hi, I have a store procedure to insert , and I use tableadapter to
execute this store procedure, when I run the application and execute the
sp , works ok
and after I see the datagridview and the new row is there, but the
problem ir that when I stop the application and look my database in SQL
Server 2005 the table dont have the new row.
Somebody knows why? or Any idea to execute the store procedure to
insert or delete or update rows in SQL Server 2005 data base using C#
2005.

Thanks a lot!!
Regards!

*** Sent via Developersdex http://www.developersdex.com ***
Jan 19 '06 #1
4 1416
Diana Estrada <es**********@yahoo.com> wrote:
Hi, I have a store procedure to insert , and I use tableadapter to
execute this store procedure, when I run the application and execute the
sp , works ok
and after I see the datagridview and the new row is there, but the
problem ir that when I stop the application and look my database in SQL
Server 2005 the table dont have the new row.
Somebody knows why? or Any idea to execute the store procedure to
insert or delete or update rows in SQL Server 2005 data base using C#
2005.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 19 '06 #2


thanks for your reply, well this is my code:

dbPrensas2006DataSetTableAdapters.spq_PrensaTableA dapter prensa = new
Prensas.dbPrensas2006DataSetTableAdapters.spq_Pren saTableAdapter();
int i = prensa.Update(ID, this.txtNombre.Text,
int.Parse(txtNumero.Text));
dbPrensas2006DataSet dsprensa = new dbPrensas2006DataSet();
prensa.Update(dsprensa);

Where:

Update execute my store procedure, this is my store procedure:

ALTER PROCEDURE spu_Prensa

(
@ID int,
@sNombre varchar(15),
@bNumero int =0
)

AS
if @ID=0
begin
insert into tPrensa (sNombre,bNumero)
values (@sNombre,@bNumero)
end
else
begin
update tPrensa
set sNombre=@sNombre, bNumero=@bNumero
where ID=@ID
end
RETURN

Thnks again, and I hope you can help me!!

*** Sent via Developersdex http://www.developersdex.com ***
Jan 19 '06 #3
Diana Estrada <es**********@yahoo.com> wrote:
thanks for your reply, well this is my code:


<snip>

Please see http://www.pobox.com/~skeet/csharp/incomplete.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 19 '06 #4
In your example it is unclear how the ID is defined; is it possible that it
is currently NULL (either null or DBNull.Value in C#) instead of 0?

If so, your SP (as written) will neither insert nor update anything; in
which case a simple change to the SP would suffice:

IF @ID = 0

becomes

IF ISNULL(@ID, 0) = 0

Marc
Jan 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Philip Boonzaaier | last post: by
16 posts views Thread by robert | last post: by
20 posts views Thread by Mark Harrison | last post: by
9 posts views Thread by anachronic_individual | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.