473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.

-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>
<asp:Parameter Name="itemID" Type="Object" />
</DeleteParameters>
<UpdateParameters>
<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" />
</UpdateParameters>
<InsertParameters>
<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" />
</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();
}
}

Apr 13 '06 #1
1 2397
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.

Regards,

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
rights.)

Apr 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: scartin | last post by:
I'm fairly new to working with ASP web controls, and am running into what seems to be a ridiculous problem that I'm hoping will be a breeze for an experienced ASP developer. I have a GridView...
1
by: Roy | last post by:
Hey all. Below is the nested syntax on how to make a "codeless" nested gridview embedded within another gridviews templatefield column. Only problem is that it loads slow. REAL SLOW. There has to...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
1
by: trint | last post by:
i have this in the html view: <asp:TemplateField HeaderText ="Remove?"> <ItemTemplate> <asp:CheckBox ID="removeSelect1" runat="server" /> </ItemTemplate> <HeaderTemplate> </HeaderTemplate>...
3
by: nick chan | last post by:
Hi i run into some difficulties getting rowupdating to fire when clicking Update link/button on gridview I set datasource at runtime, basically a datatable Edit and Cancel works. I don't know...
0
by: KeesH | last post by:
Hi, I am quite desperate now because I made a nice webshop with a gridview where the customer is able to update the amount of products (Hostas in my situation) or delete the row. The problem is...
0
by: hhoang.nl | last post by:
I have a very weird problem with the GridView control. Here is the code: <asp:GridView runat="server" ID="gv" AutoGenerateEditButton="true" AutoGenerateSelectButton="true" AllowPaging="true"...
0
by: Gilbert Tordeur | last post by:
Hello, As most of my users use a slow WAN I always write aspx pages with EnableViewState="false". However, I remark that the RowCommand and the RowDeleting routines of my GridView are not...
2
by: Gilbert Tordeur | last post by:
Hello, As most of my users use a slow WAN I always write aspx pages with EnableViewState="false" to reduce the page size. However, I remark that the RowCommand and the RowDeleting routines of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.