简体   繁体   English

在Oracle中使用XML保存数据

[英]Saving data using XML in Oracle

I use the following code for saving.Updating records to Oracle, 我使用以下代码进行保存。将记录更新到Oracle,

OracleConnection con = new OracleConnection(constr);
con.Open();

// Create the command.
OracleCommand cmd = new OracleCommand("", con);
cmd.CommandText = "<?xml version=\"1.0\"?>\n" +
    "<ROWSET>\n" +
    " <MYROW>\n" +
    " <FIELD1>2</FIELD1>\n" +
    " <FIELD2>zafar</FIELD2>\n" +
    " </MYROW>\n" +
    "</ROWSET>\n";

// Set the XML save properties.
KeyColumnsList = new string[1];
KeyColumnsList[0] = "FIELD1";
UpdateColumnsList = new string[1];
UpdateColumnsList[0] = "FIELD2";

cmd.XmlSaveProperties.KeyColumnsList = KeyColumnsList;
cmd.XmlSaveProperties.UpdateColumnsList = UpdateColumnsList;
cmd.XmlSaveProperties.RowTag = "MYROW";
cmd.XmlSaveProperties.Table = "testconn";
cmd.XmlSaveProperties.Xslt = null;
cmd.XmlSaveProperties.XsltParams = null;
rows = cmd.ExecuteNonQuery();

Console.WriteLine("rows: " + rows);

In the Field2 column I want to use select user from dual . Field2列中,我想使用select user from dual I am not able to save current DB user. 我无法保存当前的数据库用户。

The structure of data in the CommandText assumes that all values are literals. CommandText的数据结构假定所有值都是文字。 There is no way to have it recognize an inner query or expression. 无法让它识别内部查询或表达式。 If you want to query the user you will have to do it separately and incorporate that into the data. 如果要查询user ,则必须单独进行查询,然后将其合并到数据中。 This may be possible with the Xslt and XsltParams clauses. XsltXsltParams子句可能是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM