Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

INSERT or UPDATE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pxpilot - 04 Jun 2007 13:41 GMT
Hi All,
I have the a table with 2 fields: uid, date.
When the user does some activity I log his uid and the date, the
problem I have is that the table is not prepoulated with all uid's so
sometimes I need to INSERT and other times I need to UPDATE (if that
uid was already logged). Checking first with SELECT to see if the uid
exist is the obvious thing but I wonder is there a more effective way?

App is ASP.NET 2.0 in VB

Thanks
PxP
Mark Rae - 04 Jun 2007 13:53 GMT
> but I wonder is there a more effective way?

I don't believe so...

So long as the id is (part of) the primary key, the first check should be
virtually instantaneous...

Signature

http://www.markrae.net

Joey - 04 Jun 2007 14:20 GMT
> > but I wonder is there a more effective way?
>
[quoted text clipped - 4 lines]
>
> --http://www.markrae.net

Is there some sort of user registration process? If so, modify it to
insert a new record into your table. Then the registration process can
always do the insert, and the other code can always do updates.
Michael Nemtsev - 04 Jun 2007 14:56 GMT
Hello pxpilot,

It depends on your DB, some of them support MERGE (Oracle for example), which
call either insert or update.
for SQL server you need to implement your SP, there is no merge afaik

---
WBR,  Michael  Nemtsev [.NET/C# MVP].  
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

p> Hi All,
p> I have the a table with 2 fields: uid, date.
p> When the user does some activity I log his uid and the date, the
p> problem I have is that the table is not prepoulated with all uid's so
p> sometimes I need to INSERT and other times I need to UPDATE (if that
p> uid was already logged). Checking first with SELECT to see if the uid
p> exist is the obvious thing but I wonder is there a more effective
p> way?
p> App is ASP.NET 2.0 in VB
p>
p> Thanks
p> Px
Hans Kesting - 04 Jun 2007 16:55 GMT
> Hi All,
> I have the a table with 2 fields: uid, date.
[quoted text clipped - 7 lines]
> Thanks
> PxP

You could start with the UPDATE and check how many rows were updated.
If 0, then use the INSERT.
This way you execute 1 or 2 statements, instead of always 2 for the
SELECT-route.

Hans Kestin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.