Home   Free Applications   Code Snippets   Fun Stuff 
 
 You are here: Home > Code Snippets > ASP
Register   Login  

 
Site Navigation


Print Print this page
Email E-mail this page
Bookmark Add to Favorites

 
Update via Recordset Object

Posted by on Friday, October 17, 2003 (EST)

This is the ADO syntax to update a record using the "ADODB.Recordset". Also, this code will add a new record if it does not find the record to update.
Dim cn
Dim rs
ID = request("ID")
if ID = "" then ID = 0
set cn = CreateObject("ADODB.Connection")
cn.open "ODBC", "sa" ,""
sql = "Select * from TableName where ID = " & ID
set rs = CreateObject("ADODB.Recordset")
rs.open sql, cn, adOpenKeyset, adLockPessimistic, adCmdText
if RS.EOF then RS.AddNew
call genInsert("Name","Name")
rs.Update
ID = rs("ID")
rs.close
set rs = nothing
cn.close
set cn=nothing
'**********************************************************
'automates the inserting of data to an open rs recordset
'**********************************************************
Public Function genInsert(strField, strRequest)
 if request(strRequest) <> "" then
  rs(strField) = request(strRequest)
  genInsert = true
 else
  genInsert = false
 end if
 
end Function

ASP Note:
Must include "adovbs.inc" for code to run.

<!--#include file="includes/adovbs.inc"-->


Average Rating:

Add Your Comment



Top
 
CNET News.com


Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media.

  • Microsoft adding to its Labs collection
    Startup Labs will be an effort under Ray Ozzie, joining other efforts including Live Labs, adCenter Labs and Office Labs.

  • Security Bites 113: The security of Chrome
    Billy Hoffman of HP Web Security talks about Google's new browser, how it handles Javascript and what it means for Web 2.0 security.

  • Are Demo and TechCrunch50 fragmenting their audiences?
    With both events scheduled to start Monday, many press, as well as venture capitalists and others are having to choose which one to attend.

  • A user guide to following DemoFall and TechCrunch50
    More than 100 products are going to be introduced during the week of September 8. Will they be any good?

  • What's McCain doing in front of my junior high?
    Speculation has it that it was a goof-up that had the Republican nominee standing in front of Walter Reed Middle School during his acceptance speech. In any case, the image brings back memories for CNET News' Ina Fried.


    Copyright 1995-2008 CNET Networks, Inc. All rights reserved. Last Refreshed 9/5/2008 3:40:03 PM
  •