cfupdate

Description

Updates existing records in data sources.

Category

Database manipulation tags

Syntax


<cfupdate dataSource = "ds_name"

  dbType = "type"

  dbServer = "dbms"

  dbName = "database name"

  connectString = "connection string"

  tableName = "table_name"

  tableOwner = "name"

  tableQualifier = "qualifier"

  username = "username"

  password = "password"

  provider = "COMProvider" 

  providerDSN = "datasource" 

  formFields = "field_names"> 

See also

cfinsert, cfprocparam, cfprocresult, cfquery, cfqueryparam, cfstoredproc, cftransaction

Attributes

Attribute
Description
dataSource
Required for all dbType operations except dbType = "dynamic". Name of the data source that contains a table.
dbType
Optional. The database driver type:
  • dynamic    Connect to an ODBC data source that is not defined in the ColdFusion Administrator. When you use this attribute value, you must specify all the ODBC connection information using the connectstring attribute.
  • ODBC    (default) ODBC driver.
  • Oracle73    Oracle 7.3 native database driver. Using this option, the ColdFusion Server computer must have Oracle 7.3.4.0.0 (or greater) client software installed.
  • Oracle80    Oracle 8.0 native database driver. Using this option, the ColdFusion Server computer must have Oracle 8.0 (or greater) client software installed.
  • Sybase11    Sybase System 11 native database driver. Using this option, the ColdFusion Server computer must have Sybase 11.1.1 (or greater) client software installed. Sybase patch ebf 7729 is recommended.
  • OLEDB    OLE DB provider. If specified, this database provider overrides the driver type specified in the ColdFusion Administrator.
  • DB2    DB2 5.2 native database driver.
  • Informix73    Informix73 native database driver.
dbServer
Optional. For native database drivers and the SQLOLEDB provider, specifies the name of the database server computer. If specified, dbServer overrides the server specified in the data source.
dbName
Optional. The database name (Sybase System 11 driver and SQLOLEDB provider only). If specified, dbName overrides the default database specified in the data source.
connectString
Required for dbType = "dynamic"; optional for all others. The contents of a connection string to send to the ODBC server. If you are connecting to a data source defined in the ColdFusion Administrator, you can use this attribute to specify additional connection details or to override connection information specified in the Administrator. If you are dynamically connecting to a datasource by specifying dbType = "dynamic", the connection string must specify all required ODBC connection attributes.
tableName
Required. Name of the table you want to update. Note the following:
  • ORACLE drivers    This specification must be in uppercase.
  • Sybase driver    This specification is case-sensitive and must be in the same case as that used when the table was created
tableOwner
Optional. For data sources that support table ownership (for example, SQL Server, Oracle, and Sybase SQL Anywhere), use this field to specify the owner of the table.
tableQualifier
Optional. For data sources that support table qualifiers, use this field to specify the qualifier for the table. The purpose of table qualifiers varies across drivers. For SQL Server and Oracle, the qualifier refers to the name of the database that contains the table. For the Intersolv dBase driver, the qualifier refers to the directory where the DBF files are located.
username
Optional. If specified, username overrides the username value specified in the ODBC setup.
password
Optional. If specified, password overrides the password value specified in the ODBC setup.
provider
Optional. COM provider (OLE-DB only).
providerDSN
Optional. Data source name for the COM provider (OLE-DB only).
formFields
Optional. A comma-separated list of form fields to update. If this attribute is not specified, all fields in the form are included in the operation.

Example

<!--- This example shows the use of cfupdate to change

records in a data source --->



<!--- if course_ID has been passed to this form, then

perform the update on that record in the data source --->

<cfif IsDefined("form.course_ID") is "True">

<cfupdate dataSource = "cfsnippets"

tableName = "courses" formFields = "course_ID,Course_Num,Descript">

</cfif>



<!--- perform a query to reflect any updated information

if course_ID is passed through a url, we are selecting a

record to update ... select only that record with the

WHERE clause

 --->

<cfquery name = "GetCourseInfo" dataSource = "cfsnippets">

SELECT   Course_Num, Course_ID, Descript

FROM    Courses

<cfif IsDefined("url.course_ID") is True>

WHERE     Course_ID = #url.course_ID#

</cfif>

ORDER by Course_Num

</cfquery>



<html>

<head>

<title>cfupdate Example</title>

</head>



<body bgcolor = silver>

<H3>cfupdate Example</H3>



<!--- if we are updating a record, don't show

the entire list --->

<cfif NOT IsDefined("url.course_ID")>

<P><H3><a href = "cfupdate.cfm">Show Entire List</A></H3>



<form method = "POST" action = "cfupdate.cfm">



<H3>You can alter the contents of this

record, and then click "submit" to use

cfupdate and alter the database</H3>



<P>Course Number <input type = "Text" name = "number"

 value = "<cfoutput>#GetCourseInfo.Course_Num#</cfoutput>">

<P>Course Description<BR>

<TEXTAREA name = "Descript" COLS = "40" ROWS = "5">

<cfoutput>#GetCourseInfo.Descript#</cfoutput>

</TEXTAREA>

<input type = "hidden" name = "course_id"

 value = "<cfoutput>#GetCourseInfo.Course_ID#</cfoutput>">

<P><input type = "Submit" name = "">

</form>



<cfelse>

<!--- Show the entire record set in cftable form --->

<cftable query = "GetCourseInfo" HTMLTable>

<cfcol text = "<a href = 'cfupdate.cfm?course_ID = #course_ID#'>Edit Me</a>"

 width = 10 header = "Edit<br>this Entry">

<cfcol text = "#Course_Num#" width = "4" header = "Course Number">

<cfcol text = "#Descript#" width = 100 header = "Course Description">

</cftable>

</cfif>

</body>

</html>



Banner.Novgorod.Ru