views:

176

answers:

1

Hello,

A) public void GetEmployee( int EmployeeID );

<asp:ObjectDataSource  SelectMethod=”GetEmployee” …>
  <SelectParameters>
    <asp:ControlParameter Name = ”EmployeeID” ...>
  </SelectParameters>


If for whatever reason EmployeeID parameter is NULL, ObjectDataSource will convert Null to zero and passed it as argument to GetEmployee() method.

Why does runtime make such a conversion? Wouldn't throwing an exception made more sense?

B) “Use the ConvertEmptyStringToNull property to specify whether an empty string value is automatically converted to null when the data field is updated in the data source.”
I don’t quite understand the usefulness of this property. Why would empty string indicate that we want null to be inserted into source’s data field? I’d assume that this data field is of type String? Then why not also have ConvertZeroInt32ToNull etc?

bye

+4  A: 

A) It appears that the ODS is generating the default value for null of type T. In the case of an int, the default value is a 0.

B) There is no way in HTML to represent a null value via an input tag. When an emptry string is passed to an ODS and Convert Empty to Null is set to true, a null value will be set. There is no ConvertZeroToNull property since all textbox data on an HTML or Windows form is of type string.

Andrew Robinson
But wouldn't throwing an exception made more sense?
SourceC
By throwing an exception making more sense I'm referring to question A
SourceC
Not sure that an exception is the best option. If there is a case where the parameter is optional, then null -> default might be the best method of handling this. I haven't worked with an ODS in a very long time so others might better comment on this.
Andrew Robinson