The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > ASP / ASP.NET


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags:

Closed Thread
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 06-10-2007, 04:57 PM
meena
Posts: n/a
[SOLVED] How to insert and update records into access database using a single save...

...button in asp.net with c#? I have to insert records from the textboxes into a database using a SAVE button. Then using a id I'l be retrieving the data when clicking a retrieve button. Then I'l be modifying the records and update it into the database using the same SAVE button. The problem for me is using the same SAVE button for both inserting and updating.

__________________

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!
  #2 (permalink)  
Old 06-10-2007, 04: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!
  #3 (permalink)  
Old 06-10-2007, 04:58 PM
pops
Posts: n/a
conditional logic based on id

if exists id then
update
else
assign id
insert

__________________

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!
  #4 (permalink)  
Old 06-10-2007, 04:58 PM
pops
Posts: n/a
conditional logic based on id

if exists id then
update
else
assign id
insert

__________________

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!
Closed Thread


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 12:46 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50