[Mono-bugs] [Bug 55162][Blo] Changed - SqlParameter value set to null will not result in NULL in query.
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Wed, 31 Mar 2004 05:57:36 -0500 (EST)
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 frans@sd.nl.
http://bugzilla.ximian.com/show_bug.cgi?id=55162
--- shadow/55162 2004-03-31 05:09:44.000000000 -0500
+++ shadow/55162.tmp.15860 2004-03-31 05:57:36.000000000 -0500
@@ -76,6 +76,42 @@
System.DBNull.Value as the field's value if a field is NULL.
------- Additional Comments From lluis@ximian.com 2004-03-31 05:09 -------
I guess this comment is about bug 55161, not about this one. Anyway,
by test case I mean a self-contained test that can be run to reproduce
the problem.
+
+------- Additional Comments From frans@sd.nl 2004-03-31 05:57 -------
+Whoops my bad. (well, you now have example code for the other bug).
+
+A selfcontained example:
+
+try to execute the query string:
+UPDATE Orders SET EmployeeID = @EmployeeID WHERE OrderID=@OrderID
+
+using an SqlCommand object.
+The @Parameter parameter is added like this:
+SqlConnection conn = new SqlConnection(_connectionString);
+SqlCommand command = new SqlCommand("UPDATE Orders SET EmployeeID =
+@EmployeeID WHERE OrderID=@OrderID", conn);
+command.Parameters.Add(new SqlParameter("@EmployeeID", SqlDbType.Int,
+0, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Current,
+null);
+command.Parameters.Add(new SqlParameter("@OrderID", SqlDbType.Int, 0,
+ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Current,
+10254);
+
+conn.Open();
+
+// execute the command
+command.ExecuteNonQuery();
+
+conn.Close();
+
+This will fail, as the SQL generated by the SqlClient will simply
+generate @EmployeeID=, and not as the SqlClient in .NET does:
+(Oracle's ODP.NET also correctly generates NULL values)
+@EmployeeID=NULL, as I quoted.
+
+So a statement in the parameter sql generation of the SqlParameter
+should be added which checks for null as value. If so, it should pass
+NULL as the value.