NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

A Quick Way to Save Data

Written by Eric Smith, Northstar Computer Systems LLC

Here's a subroutine that uses ADO within a COM component to save data from the object back to a database recordset. This code makes the assumption that there is a property with the same name as each database field. The code also takes care of cases in which there is a non-editable field, such as a counter. The code will skip these by using the Attributes property of the field. Make sure the recordset is opened to the record being edited before calling this code.
Public Sub SaveObject(objInput As Object, rsInput As ADODB.Recordset)
   Dim objField As ADODB.Field
   Dim varResult As Variant
   
   For Each objField In rsInput.Fields
      If objField.Attributes And adFldUpdatable Then
         varResult = CallByName(objInput, objField.Name, VbGet)
         If TypeName(varResult) <> "String" Then
            rsInput(objField.Name) = varResult
         ElseIf varResult <> "" Then
            rsInput(objField.Name) = varResult
         Else
            rsInput(objField.Name) = ""
         End If
      End If
   Next objField

End Sub

Keywords: [ Active Data Objects | COM, DCOM, COM+ ]

Publication Date: 7/1/1999, Last Update: 2/12/2010