ConvertEmptyStr ingToNull="fals e" ?
I have a custom data class and am passing values to it via an ODS. On my
insert, if the bound text box is empty an empty string or "" is passed to my
data object. On an update, an empty string is converted to null.
The insert does not use the ConvertEmptyStr ingToNull="fals e" property and
works the way I was hoping. Setting this property on the update parameters
in the ODS seems to have no affect.
Thanks for any help or ideas. I really don't want to check for nulls in my
data object for each field.
-Andrew
<asp:ObjectData Source ID="ObjectDataS ourceMain" runat="server"
DeleteMethod="D elete" InsertMethod="I nsert"
OnInserting="Ob jectDataSourceM ain_Inserting"
OnSelected="Obj ectDataSourceMa in_Selected" SelectMethod="S elect"
TypeName="Marke tStreet.Data.It emData" UpdateMethod="U pdate">
<DeleteParamete rs>
<asp:Paramete r Name="itemID" Type="Object" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="itemID" Type="Object" />
<asp:Paramete r Name="itemDescr iption1" Type="String" />
<asp:Paramete r Name="itemDescr iption2" Type="String" />
<asp:Paramete r Name="itemNote" Type="String"
ConvertEmptyStr ingToNull="fals e" />
<asp:Paramete r Name="itemCode" Type="String" />
<asp:Paramete r Name="itemPrice " Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="itemDescr iption1" Type="String" />
<asp:Paramete r Name="itemDescr iption2" Type="String" />
<asp:Paramete r Name="itemNote" Type="String" />
<asp:Paramete r Name="itemCode" Type="String" />
<asp:Paramete r Name="itemPrice " Type="String" />
</InsertParameter s>
[DataObjectMetho d(DataObjectMet hodType.Update, true)]
public void Update(object itemID, string itemDescription 1, string
itemDescription 2, string itemNote, string itemCode, string itemPrice)
{
// itemNote is NULL here.
using (SqlConnection cn = new SqlConnection(D ataConnection))
using (SqlCommand cm = new SqlCommand("UPD ATE Item SET
ItemDescription 1=@description1 , ItemDescription 2=@description2 ,
ItemNote=@note, ItemCode=@code, ItemPrice=@pric e WHERE ItemID=@itemID" , cn))
{
cn.Open();
cm.CommandType = CommandType.Tex t;
cm.Parameters.A ddWithValue("@i temID", itemID);
cm.Parameters.A ddWithValue("@d escription1",
itemDescription 1);
cm.Parameters.A ddWithValue("@d escription2",
itemDescription 2);
cm.Parameters.A ddWithValue("@n ote", itemNote);
cm.Parameters.A ddWithValue("@c ode", itemCode);
cm.Parameters.A ddWithValue("@p rice", itemPrice);
cm.ExecuteNonQu ery();
cn.Close();
}
}