Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>a)Any idea why T1’s empty string gets converted, while T2’s doesn’t?</p> </blockquote> <p>T2 is a DateTime which is a value type. Value types can't be null. Well unless you use the <a href="http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx" rel="nofollow noreferrer">Nullable type</a></p> <blockquote> <p>b) Also, how can I prevent the conversion( BTW - I realize I could convert null back to empty string inside update method )?</p> </blockquote> <p><strong>EDIT:</strong> I've tried to duplicate the problem above, but I could only duplicate the problem when I didn't specify <code>ConvertEmptyStringToNull="false"</code> in the <code>&lt;asp:TemplateField&gt;</code> of the bound control <strong>AND</strong> the <code>&lt;asp:Parameter&gt;</code> of the <code>&lt;asp:ObjectDataSource&gt;</code>. If you leave either out then you will get the null value on an empty field. With the <code>ConvertEmptyStringToNull="false"</code> defined in both places it does not convert the empty string to a null value. The empty string is passed correctly. You said that you did try it in both places, so I'm not sure why it's not working for you. Maybe you could show us your datasource and detailsview markup.</p> <p>With that said I think it is still a good idea to make the check described below in your business class. Like you said you can convert null back to an empty string. This is how I have done it:</p> <p>I have a helper class, lets call it BizObject, that contains this method:</p> <pre><code>protected static string ConvertNullToEmptyString(string input) { return (input == null ? "" : input); } </code></pre> <p>Then in my business class's Insert/Update method I call ConvertNullToEmptyString on each string parameter:</p> <pre><code>public static bool UpdateSource(string sourceName, DateTime sourceDate) { sourceName = BizObject.ConvertNullToEmptyString(sourceName); ... bool ret = UpdateSource(record); return ret; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload