Thread: update info
View Single Post
  #2 (permalink)  
Old July 4th, 2009, 04:48 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Hi there,

You can close the reader by calling Close() on it.

However, in your situation there's a better alternative. Don't check up front if the record exists. Just perform a regular UPDATE immediately without executing a SELECT first, and then check the return value of ExecuteNonQuery to see if any records were affected.

Code:
 
if (cmdUpdate.ExecuteNonQuery() > 0)
{
  // found
}
else
{
  // not found
}
More info:
http://msdn.microsoft.com/en-us/libr...enonquery.aspx


Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Reply With Quote