View Single Post
  #2 (permalink)  
Old 06-10-2007, 05:57 PM
Smutty Smutty is offline
Novice
Join Date: Jun 2007
Posts: 9
iTrader: (0)
Smutty is on a distinguished road
Assuming that your table is MyTable( MyId, MyField1, MyField2 ) here is a solution through defining a Stored Procedure which has the structure to be shown later.

Whenever the button Save is clicked, all you have to do is call the procedure SaveMyTable.

If you are inserting a record, set the parameter @prmId of the procedure to 0.
If you are updating a record, set the parameter @prmId to the value of the record's Id you want to update.

Code of the Stored Procedure:

CREATE PROCEDURE SaveMyTable
(
@prmId int,
@prmField1 varchar(100), -- assuming MyField1 is of type varchar(100),
@prmField2 smalldatetime -- assume MyField2 is of type smalldatetime
)
AS
IF (@prmId = 0)
-- Insert new record to Table
INSERT INTO MyTable (MyField1, MyField2) VALUES ( @prmField1, @prmField2) -- assuming MyId is an Identity

ELSE
-- update an existing record
UPDATE MyTable
SET
MyField1 = @prmField1,
MyField2 = @prmField2
WHERE
MyId = @prmId

Hope this helps.

__________________
Powered by Yahoo! Answers
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!