Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2005, 02:18 PM
Authorized User
 
Join Date: Jan 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Designing Classes

Hi, programming newbie here - I have an architecture question regarding OOP.

So I have a "customer" class. I want to be able to create a customer object to retrieve an existing customers info, but update and existing customer and add a new one. here is an example of the fields:

First Name
Last Name
Address 1
Address 2
Email

So, what is the best way to design this class? The thing i am struggiling with is the updating the database part. How can this class make a new customer or update an existing one? I mean differentiate between the two functions - knowing which it needs to do.

Also, field definitaions and protetion levels are confusing to me. What fields are internal, and what are public, and what are get/set and what cases/notation do i assign each.

THank you for your help!

-- Jennifer Quick
 
Old February 28th, 2005, 01:13 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Class design aside, there is a pretty simple way of determining whether to update or create data.

In many of my scenarios, I write a method to update or save class data. The first part of the method creates an UPDATE SQL query and executes it. If rows affected by the execute is 0 then I know that the update criteria was not found indicating that the record does not yet exist. So I then generate an INSERT query and execute that.

This technique saves the step of checking to see that the record exists and then running an UPDATE or INSERT based on that. In many cases you are doing an update so you'll just have the single UPDATE query to execute and all will be fine. However, in some cases you might be performing far more INSERTs than UPDATEs. For these cases you should create methods specifically for inserting data only.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
some help designing my database lord_midnight BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 0 November 8th, 2008 11:39 AM
web designing werstyle teen HTML Code Clinic 0 November 22nd, 2006 05:33 AM
database designing mukund SQL Server 2000 1 December 23rd, 2004 12:14 AM
help in designing a database rose77 SQL Server 2000 3 December 7th, 2004 12:38 PM
Designing data access classes in ASP.NET shawnm ASP.NET 1.x and 2.0 Application Design 3 August 4th, 2004 02:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.