An OracleXmlSaveProperties
object represents the XML properties used by the OracleCommand
class when the XmlCommandType
property is Insert
, Update
, or Delete
.
System.Object
System.OracleXmlSaveProperties
public sealed class OracleXmlSaveProperties : ICloneable
Provider | ODP.NET, Unmanaged Driver |
Assembly | Oracle.DataAccess.dll |
Namespace | Oracle.DataAccess.Client |
.NET Framework | 3.5, 4.0, 4.5 |
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
OracleXmlSaveProperties
can be accessed and modified using the XmlSaveProperties
property of the OracleCommand
class. Each OracleCommand
object has its own instance of the OracleXmlSaveProperties
class in the XmlSaveProperties
property.
Use the default constructor to get a new instance of OracleXmlSaveProperties
. Use the OracleXmlSaveProperties
.Clone()
method to get a copy of an OracleXmlSaveProperties
instance.
This sample demonstrates how to do inserts, updates, and deletes to a relational table or view using an XML document.
// C# /* -- If HR account is being locked, you need to log on as a DBA -- to unlock the account first. Unlock a locked users account: ALTER USER hr ACCOUNT UNLOCK; */ using System; using Oracle.DataAccess.Client; class OracleXmlSavePropertiesSample { static void Main() { string[] KeyColumnsList = null; string[] UpdateColumnsList = null; int rows = 0; // Create the connection. string constr = "User Id=hr;Password=hr;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); // Create the command. OracleCommand cmd = new OracleCommand("", con); // Set the XML command type to insert. cmd.XmlCommandType = OracleXmlCommandType.Insert; // Set the XML document. cmd.CommandText = "<?xml version=\"1.0\"?>\n" + "<ROWSET>\n" + " <MYROW num = \"1\">\n" + " <EMPLOYEE_ID>1234</EMPLOYEE_ID>\n" + " <LAST_NAME>Smith</LAST_NAME>\n" + " <EMAIL>Smith@Oracle.com</EMAIL>\n" + " <HIRE_DATE>1982-01-23T00:00:00.000</HIRE_DATE>\n" + " <JOB_ID>IT_PROG</JOB_ID>\n" + " </MYROW>\n" + " <MYROW num = \"2\">\n" + " <EMPLOYEE_ID>1235</EMPLOYEE_ID>\n" + " <LAST_NAME>Barney</LAST_NAME>\n" + " <EMAIL>Barney@Oracle.com</EMAIL>\n" + " <HIRE_DATE>1982-01-23T00:00:00.000</HIRE_DATE>\n" + " <JOB_ID>IT_PROG</JOB_ID>\n" + " </MYROW>\n" + "</ROWSET>\n"; // Set the XML save properties. KeyColumnsList = new string[1]; KeyColumnsList[0] = "EMPLOYEE_ID"; UpdateColumnsList = new string[5]; UpdateColumnsList[0] = "EMPLOYEE_ID"; UpdateColumnsList[1] = "LAST_NAME"; UpdateColumnsList[2] = "EMAIL"; UpdateColumnsList[3] = "HIRE_DATE"; UpdateColumnsList[4] = "JOB_ID"; cmd.XmlSaveProperties.KeyColumnsList = KeyColumnsList; cmd.XmlSaveProperties.RowTag = "MYROW"; cmd.XmlSaveProperties.Table = "employees"; cmd.XmlSaveProperties.UpdateColumnsList = UpdateColumnsList; cmd.XmlSaveProperties.Xslt = null; cmd.XmlSaveProperties.XsltParams = null; // Do the inserts. rows = cmd.ExecuteNonQuery(); Console.WriteLine("rows: " + rows); // Set the XML command type to update. cmd.XmlCommandType = OracleXmlCommandType.Update; // Set the XML document. cmd.CommandText = "<?xml version=\"1.0\"?>\n" + "<ROWSET>\n" + " <MYROW num = \"1\">\n" + " <EMPLOYEE_ID>1234</EMPLOYEE_ID>\n" + " <LAST_NAME>Adams</LAST_NAME>\n" + " </MYROW>\n" + "</ROWSET>\n"; // Set the XML save properties. KeyColumnsList = new string[1]; KeyColumnsList[0] = "EMPLOYEE_ID"; UpdateColumnsList = new string[1]; UpdateColumnsList[0] = "LAST_NAME"; cmd.XmlSaveProperties.KeyColumnsList = KeyColumnsList; cmd.XmlSaveProperties.UpdateColumnsList = UpdateColumnsList; rows = cmd.ExecuteNonQuery(); Console.WriteLine("rows: " + rows); // Set the XML command type to delete. cmd.XmlCommandType = OracleXmlCommandType.Delete; // Set the XML document. cmd.CommandText = "<?xml version=\"1.0\"?>\n" + "<ROWSET>\n" + " <MYROW num = \"1\">\n" + " <EMPLOYEE_ID>1234</EMPLOYEE_ID>\n" + " </MYROW>\n" + " <MYROW num = \"2\">\n" + " <EMPLOYEE_ID>1235</EMPLOYEE_ID>\n" + " </MYROW>\n" + "</ROWSET>\n"; // Set the XML save properties. KeyColumnsList = new string[1]; KeyColumnsList[0] = "EMPLOYEE_ID"; cmd.XmlSaveProperties.KeyColumnsList = KeyColumnsList; cmd.XmlSaveProperties.UpdateColumnsList = null; // Do the deletes. rows = cmd.ExecuteNonQuery(); Console.WriteLine("rows: " + rows); // Clean up. cmd.Dispose(); con.Close(); con.Dispose(); } }
See Also:
OracleXmlSaveProperties
members are listed in the following tables.
OracleXmlSaveProperties Constructor
OracleXmlSaveProperties
constructors are listed in Table 7-7
Table 7-7 OracleXmlSaveProperties Constructor
Constructor | Description |
---|---|
Instantiates a new instance of the |
OracleXmlSaveProperties Properties
The OracleXmlSaveProperties
properties are listed in Table 7-8.
Table 7-8 OracleXmlSaveProperties Properties
Name | Description |
---|---|
Specifies the list of columns used as a key to locate existing rows for update or delete using an XML document |
|
Specifies the value for the XML element that identifies a row of data in an XML document |
|
Specifies the name of the table or view to which changes are saved |
|
Specifies the list of columns to update or insert |
|
Specifies the XSL document used for XML transformation using XSLT |
|
Specifies the parameters for the XSLT document specified in the Xslt property |
OracleXmlSaveProperties Public Methods
The OracleXmlSaveProperties
public methods are listed in Table 7-9.
The OracleXmlSaveProperties
constructor instantiates a new instance of OracleXmlSaveProperties
class.
// C# public OracleXmlSaveProperties;
The OracleXmlSaveProperties
properties are listed in Table 7-10.
Table 7-10 OracleXmlSaveProperties Properties
Name | Description |
---|---|
Specifies the list of columns used as a key to locate existing rows for update or delete using an XML document |
|
Specifies the value for the XML element that identifies a row of data in an XML document |
|
Specifies the name of the table or view to which changes are saved |
|
Specifies the list of columns to update or insert |
|
Specifies the XSL document used for XML transformation using XSLT |
|
Specifies the parameters for the XSLT document specified in the Xslt property |
See Also:
This property specifies the list of columns used as a key to locate existing rows for update or delete using an XML document.
// C# public string[] KeyColumnsList {get; set;}
The list of columns.
Default value is null.
The first null value (if any) terminates the list.
KeyColumnsList
usage with XMLCommandType
property values:
Insert
- KeyColumnsList
is ignored and can be null.
Update
- KeyColumnsList
must be specified; it identifies the columns to use to find the rows to be updated.
Delete
- If KeyColumnsList
is null, all the column values in each row element in the XML document are used to locate the rows to delete. Otherwise, KeyColumnsList
specifies the columns used to identify the rows to delete.
This property specifies the value for the XML element that identifies a row of data in an XML document.
// C# public string RowTag {get; set;}
An XML element name.
The default value is ROW
.
Each element in the XML document identifies one row in a table or view.
If RowTag
is set to ""
or null
, no row tag is used in the XML document. In this case, the XML document is assumed to contain only one row.
This property specifies the name of the table or view to which changes are saved.
// C# public string Table {get; set;}
A table name.
Default value is null
.
The property must be set to a valid table or view name.
This property specifies the list of columns to update or insert.
// C# public string[] UpdateColumnsList {get; set;}
A list of columns.
Default value is null.
The first null value (if any) terminates the list.
UpdateColumnList
usage with XMLCommandType
property values:
Insert
- UpdateColumnList
indicates which columns are assigned values when a new row is created. If UpdateColumnList
is null, then all columns are assigned values. If a column is on the UpdateColumnList
, but no value is specified for the row in the XML file, then NULL
is used. If a column is not on the UpdateColumnList
, then the default value for that column is used.
Update
- UpdateColumnList
specifies columns to modify for each row of data in the XML document. If UpdateColumnList
is null, all the values in each XML element in the XML document are used to modify the columns.
Delete
- UpdateColumnsList
is ignored and can be null.
This property specifies the XSL document used for XML transformation using XSLT.
// C# public string Xslt {get; set;}
The XSL document used for XML transformation.
Default = null
.
The XSL document is used for XSLT transformation of a given XML document. The transformed XML document is used to save changes to the table or view.
This property specifies the parameters for the XSLT document specified in the Xslt
property.
// C# public string XsltParams {get; set;}
The parameters for the XSLT document.
Default is null
.
This property is a string delimited by semicolons in "name=value
" pairs of the form "param1=value1; param2=value2; …
".
The OracleXmlSaveProperties
public methods are listed in Table 7-11.
Table 7-11 OracleXmlSaveProperties Public Methods
Name | Description |
---|---|
Creates a copy of an |