2007-05-02 Igor Zelmanovich <igorz@mainsoft.com>
authorIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Wed, 2 May 2007 09:46:07 +0000 (09:46 -0000)
committerIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Wed, 2 May 2007 09:46:07 +0000 (09:46 -0000)
* SqlDataSourceView.cs:
make CancelSelectOnNullParameter property works.

svn path=/trunk/mcs/; revision=76559

mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs

index 4b6bf4e85acd4773ca2f06efdb157149856efa23..f2d45935b6569282a7b9a408234c77144d7bfcee 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-02 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * SqlDataSourceView.cs:
+       make CancelSelectOnNullParameter property works.
+
 2007-05-01  Marek Habersack  <mhabersack@novell.com>
 
        * BaseValidator.cs: do not use User-Agent directly, we must take
index 40304e16c12f0d806b77f46f577c775ca279e3df..5dbb19e03aa619b4e9bfb9dc33fcaa7a38b68038 100644 (file)
@@ -229,7 +229,7 @@ namespace System.Web.UI.WebControls {
                                if (dataView == null) {
                                        SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
                                        OnSelecting (selectingArgs);
-                                       if (selectingArgs.Cancel) {
+                                       if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
                                                return null;
                                        }
                                        try {
@@ -279,7 +279,7 @@ namespace System.Web.UI.WebControls {
                        else {
                                SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
                                OnSelecting (selectingArgs);
-                               if (selectingArgs.Cancel) {
+                               if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
                                        return null;
                                }
 
@@ -304,6 +304,20 @@ namespace System.Web.UI.WebControls {
                        }
                }
 
+               static bool PrepareNullParameters (DbCommand command, bool cancelIfHas)
+               {
+                       for (int i = 0; i < command.Parameters.Count; i++) {
+                               DbParameter param = command.Parameters [i];
+                               if (param.Value == null && ((param.Direction & ParameterDirection.Input) != 0)) {
+                                       if (cancelIfHas)
+                                               return false;
+                                       else
+                                               param.Value = DBNull.Value;
+                               }
+                       }
+                       return true;
+               }
+
                public int Update (IDictionary keys, IDictionary values, IDictionary oldValues)
                {
                        return ExecuteUpdate (keys, values, oldValues);
@@ -450,10 +464,7 @@ namespace System.Web.UI.WebControls {
                {
                        DbParameter dbp = factory.CreateParameter ();
                        dbp.ParameterName = ParameterPrefix + name;
-                       if (value == null)
-                               dbp.Value = DBNull.Value;
-                       else
-                               dbp.Value = value;
+                       dbp.Value = value;
                        dbp.Direction = dir;
                        if (size != -1)
                                dbp.Size = size;