[Mono-bugs] [Bug 75041][Nor] New - Binding OdbcCommand.Parameters with Type OdbcType.Decimal

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed May 25 10:16:25 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by timo-mono at pokorra.de.

http://bugzilla.ximian.com/show_bug.cgi?id=75041

--- shadow/75041	2005-05-25 10:16:25.000000000 -0400
+++ shadow/75041.tmp.26423	2005-05-25 10:16:25.000000000 -0400
@@ -0,0 +1,72 @@
+Bug#: 75041
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.Data
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: timo-mono at pokorra.de               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Binding OdbcCommand.Parameters with Type OdbcType.Decimal
+
+Description of Problem:
+Binding OdbcCommand.Parameters with Type OdbcType.Decimal will execute the
+sql query, but for example when done with an update query, the value of the
+column will be 0.
+
+Steps to reproduce the problem:
+odbccmd = new OdbcCommand("UPDATE myTable SET myNumeric = ?", dbcon);
+odbccmd.CommandType = CommandType.Text;
+odbccmd.Parameters.Add("decPartnerKey", OdbcType.Decimal, 10);
+odbccmd.Parameters["decPartnerKey"].Value = 29000000;
+odbccmd.ExecuteScalar();
+
+Actual Results:
+The column myNumeric will be 0.
+
+Expected Results:
+Should have the value, e.g. 29000000
+
+How often does this happen? 
+Always
+
+Additional Information:
+I tried very hard, to make it work. 
+I had a look here, for binding decimal parameters in C:
+http://www.it-faq.pl/mskb/181/254.HTM
+But I could not get it work with c#.
+My solution for the moment is to modify OdbcCommand.cs, the Prepare()
+function, to modify the sql string and insert the parameters into the string:
+
++int i=1;
++foreach (OdbcParameter p in Parameters)
++{
++  int pos = CommandText.IndexOf("?");
++  CommandText = CommandText.Substring(0, pos-1) + p.ValueToString() +
+CommandText.Substring(pos+1);
++  i++;
++}
++prepared = false;
++return;
+
+in OdbcParameter.cs:
++public string ValueToString()
++{
++string paramValueString = Value.ToString();
++//not sure about Bit, databases treat it differently
++if (odbcType == OdbcType.Bit)
++	paramValueString = (System.Convert.ToBoolean(Value.ToString()) ? 1 :
+0).ToString();
++// Treat everything else as a string
++// Init string buffer
++if (Value is String)
++	paramValueString = "\'"+paramValueString+"\'";
++return paramValueString;                                        
++}


More information about the mono-bugs mailing list