A
Andrew Robinson
Woundering if anyone else has had issues with
ConvertEmptyStringToNull="false" ?
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 ConvertEmptyStringToNull="false" 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:ObjectDataSource ID="ObjectDataSourceMain" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OnInserting="ObjectDataSourceMain_Inserting"
OnSelected="ObjectDataSourceMain_Selected" SelectMethod="Select"
TypeName="MarketStreet.Data.ItemData" UpdateMethod="Update">
<DeleteParameters>
<asparameter Name="itemID" Type="Object" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="itemID" Type="Object" />
<asparameter Name="itemDescription1" Type="String" />
<asparameter Name="itemDescription2" Type="String" />
<asparameter Name="itemNote" Type="String"
ConvertEmptyStringToNull="false" />
<asparameter Name="itemCode" Type="String" />
<asparameter Name="itemPrice" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="itemDescription1" Type="String" />
<asparameter Name="itemDescription2" Type="String" />
<asparameter Name="itemNote" Type="String" />
<asparameter Name="itemCode" Type="String" />
<asparameter Name="itemPrice" Type="String" />
</InsertParameters>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public void Update(object itemID, string itemDescription1, string
itemDescription2, string itemNote, string itemCode, string itemPrice)
{
// itemNote is NULL here.
using (SqlConnection cn = new SqlConnection(DataConnection))
using (SqlCommand cm = new SqlCommand("UPDATE Item SET
ItemDescription1=@description1, ItemDescription2=@description2,
ItemNote=@note, ItemCode=@code, ItemPrice=@price WHERE ItemID=@itemID", cn))
{
cn.Open();
cm.CommandType = CommandType.Text;
cm.Parameters.AddWithValue("@itemID", itemID);
cm.Parameters.AddWithValue("@description1",
itemDescription1);
cm.Parameters.AddWithValue("@description2",
itemDescription2);
cm.Parameters.AddWithValue("@note", itemNote);
cm.Parameters.AddWithValue("@code", itemCode);
cm.Parameters.AddWithValue("@price", itemPrice);
cm.ExecuteNonQuery();
cn.Close();
}
}
ConvertEmptyStringToNull="false" ?
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 ConvertEmptyStringToNull="false" 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:ObjectDataSource ID="ObjectDataSourceMain" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OnInserting="ObjectDataSourceMain_Inserting"
OnSelected="ObjectDataSourceMain_Selected" SelectMethod="Select"
TypeName="MarketStreet.Data.ItemData" UpdateMethod="Update">
<DeleteParameters>
<asparameter Name="itemID" Type="Object" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="itemID" Type="Object" />
<asparameter Name="itemDescription1" Type="String" />
<asparameter Name="itemDescription2" Type="String" />
<asparameter Name="itemNote" Type="String"
ConvertEmptyStringToNull="false" />
<asparameter Name="itemCode" Type="String" />
<asparameter Name="itemPrice" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="itemDescription1" Type="String" />
<asparameter Name="itemDescription2" Type="String" />
<asparameter Name="itemNote" Type="String" />
<asparameter Name="itemCode" Type="String" />
<asparameter Name="itemPrice" Type="String" />
</InsertParameters>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public void Update(object itemID, string itemDescription1, string
itemDescription2, string itemNote, string itemCode, string itemPrice)
{
// itemNote is NULL here.
using (SqlConnection cn = new SqlConnection(DataConnection))
using (SqlCommand cm = new SqlCommand("UPDATE Item SET
ItemDescription1=@description1, ItemDescription2=@description2,
ItemNote=@note, ItemCode=@code, ItemPrice=@price WHERE ItemID=@itemID", cn))
{
cn.Open();
cm.CommandType = CommandType.Text;
cm.Parameters.AddWithValue("@itemID", itemID);
cm.Parameters.AddWithValue("@description1",
itemDescription1);
cm.Parameters.AddWithValue("@description2",
itemDescription2);
cm.Parameters.AddWithValue("@note", itemNote);
cm.Parameters.AddWithValue("@code", itemCode);
cm.Parameters.AddWithValue("@price", itemPrice);
cm.ExecuteNonQuery();
cn.Close();
}
}