Do not use on any
shared computer
July 25, 2008 06:03am pdt
null
[x]
Attachment Details

Why aren't my Bind variables being processed correctly?

Tags: Oracle, 11g, 11g, Accessed via ODP.NET
Hi,
 
   I have a table in Oracle 11g that holds an XML document (as XMLType) and another column tha contains a GUID that services as the primary key.  I have method that accepts a GUID and an XML document as an input and replaces the stored XML document that is associated with the submitted GUID (this is a simple udpate function).  

When I build the query withouth using Bind variables it works fine, but when I use bind variables the GUID never gets successfully matched with a GUID in the table and does not update anything in the tables (it doesn't throw any exceptions either).  Please see the below C# code that I have that does not work.  Any suggestions as to what I'm doing wrong?  

As I mentioned before, when I replace the string sqlStatement with "UPDATE DOCUMENT SET XML_DOC = :xmlDoc_var WHERE UUID = " + "'" + UUID + "'"; it works just fine.

Thanks,
Pat
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
public bool UpdateDoc(string xmlDocument, string UUID)
{
 
string sqlStatement = "UPDATE DOCUMENT SET XML_DOC = :xmlDoc_var WHERE UUID = :UUID_var";
 
//This is a helper class that returns an OracleConnection object
OracleConnection conn = Helper.getConnectionObject();
 
try
{
//Set the OracleCommand object and open the connection
OracleCommand oraCommand = new OracleCommand(sqlStatement, conn);
conn.Open();
 
//Create the OracleXmlType object and set it to the xmlDocument 
//passed into the method
OracleXmlType xmlType = new OracleXmlType(conn, xmlDocument);
 
//Set the bind variables
oraCommand.Parameters.Add(":xmlDoc_var", xmlType);
oraCommand.Parameters.Add(":UUID_var", UUID);
 
//Execute the query
int result = oraCommand.ExecuteNonQuery();
conn.Close();
oraCommand.Dispose();
return true;
}
 
catch (Exception e)
{
Helper.logError(e);
if (null != conn && conn.State == ConnectionState.Open) conn.Close();
return false;
}
 
}
Start your free trial to view this solution
Question Stats
Zone: Database
Question Asked By: pbenito
Question Asked On: 03.07.2008
Participating Experts: 1
Points: 500
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by schwertner
Expert Comment by schwertner:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pbenito
Author Comment by pbenito:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by schwertner
Expert Comment by schwertner:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by schwertner
Expert Comment by schwertner:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pbenito
Author Comment by pbenito:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628