469,927 Members | 1,235 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

GridView ODS and ConvertEmptyStringToNull="false"

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.


<asp:ObjectDataSource ID="ObjectDataSourceMain" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OnSelected="ObjectDataSourceMain_Selected" SelectMethod="Select"
TypeName="MarketStreet.Data.ItemData" UpdateMethod="Update">
<asp:Parameter Name="itemID" Type="Object" />
<asp:Parameter Name="itemID" Type="Object" />
<asp:Parameter Name="itemDescription1" Type="String" />
<asp:Parameter Name="itemDescription2" Type="String" />
<asp:Parameter Name="itemNote" Type="String"
ConvertEmptyStringToNull="false" />
<asp:Parameter Name="itemCode" Type="String" />
<asp:Parameter Name="itemPrice" Type="String" />
<asp:Parameter Name="itemDescription1" Type="String" />
<asp:Parameter Name="itemDescription2" Type="String" />
<asp:Parameter Name="itemNote" Type="String" />
<asp:Parameter Name="itemCode" Type="String" />
<asp:Parameter Name="itemPrice" Type="String" />

[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))

cm.CommandType = CommandType.Text;
cm.Parameters.AddWithValue("@itemID", itemID);
cm.Parameters.AddWithValue("@note", itemNote);
cm.Parameters.AddWithValue("@code", itemCode);
cm.Parameters.AddWithValue("@price", itemPrice);



Apr 13 '06 #1
1 2221
Hi Andrew,

Thanks you for posting.

As for the ObjectDataSource control parameter's ConvertEmptyStringToNull
setting problem, it is actually due to the separate
ConvertEmptyStringToNull setting for DataSource Control and DataBound
control. For DataSource control(such as objectdatasource), each parameter
has the "ConvertEmptyStringToNull" setting. However, in DataBound control,
like GridView, each DataBoundField(BoundField, TemplateField...) also has
such a "ConvertEmptyStringToNull" property. So for update operation in
GridView, the value first be extracted from GridView's field into
datavalues, then passed to ObjectDataSource, so if we want let the
emptystring be perserved, we should also configure the
"ConvertEmptyStringToNull" on the Field in GridView. e.g:

<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
ConvertEmptyStringToNull="False" />

Hope this helps.


Steven Cheng
Microsoft Online Community Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no

Apr 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by trint | last post: by
3 posts views Thread by nick chan | last post: by
reply views Thread by hhoang.nl | last post: by
2 posts views Thread by Gilbert Tordeur | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.