Note that there are some explanatory texts on larger screens.

plurals
  1. POFailed update on custom binding format datetime using EntityDataSource
    primarykey
    data
    text
    <p><em>Perhaps this is one of error that was made by a team of ASP.NET developers.</em></p> <p>I have made data model <strong>Celengan</strong> like this, format (<em>ColumnName: Type</em>) :</p> <pre><code>Celengan CelenganID: System.Int32 [PK] .. // means other field .. // means other field TanggalPemberian: System.DateTime TanggalPengembalian: System.DateTime .. </code></pre> <p>Then, i created very simple CRUD application on GridView by creating one GridView and EntityDataSource. This my entitydatasource design code from my page (Celengan.aspx) :</p> <pre><code>&lt;asp:EntityDataSource ID="CelenganEntityDataSource" runat="server" ConnectionString="name=SmatContext" DefaultContainerName="SmatContext" EnableFlattening="False" EntitySetName="Celengans" Include="Perusahaan" EnableDelete="True" EnableUpdate="True"&gt;&lt;/asp:EntityDataSource&gt; </code></pre> <p>Looked, i enable two command: <code>EnableDelete="True"</code>, and <code>EnableUpdate="True"</code></p> <p>And this is my GridView design code:</p> <pre><code>&lt;asp:GridView ID="CelenganGridView" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="5" DataKeyNames="CelenganID" DataSourceID="CelenganEntityDataSource" ShowHeaderWhenEmpty="True"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="CelenganID" HeaderText="ID" ReadOnly="True" SortExpression="CelenganID" &gt; &lt;asp:TemplateField HeaderText="Tanggal Pemberian" SortExpression="TanggalPemberian"&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Text='&lt;%# Bind("TanggalPemberian", "{0:dd/MM/yyyy}") %&gt;' Width="80px"&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Bind("TanggalPemberian", "{0:dd/MM/yyyy}") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Tanggal Pengembalian" SortExpression="TanggalPengembalian"&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="TextBox2" runat="server" Text='&lt;%# Bind("TanggalPengembalian", "{0:dd/MM/yyyy}") %&gt;' Width="80px"&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="Label4" runat="server" Text='&lt;%# Bind("TanggalPengembalian", "{0:dd/MM/yyyy}") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;asp:TemplateField ShowHeader="False"&gt; &lt;EditItemTemplate&gt; &lt;asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Update" Text="Save" &gt;&lt;/asp:LinkButton&gt; &lt;asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" &gt;&lt;/asp:LinkButton&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" &gt;&lt;/asp:LinkButton&gt; &lt;asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Apakah celengan ini akan di hapus ?');"&gt;&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>That its, because of my country (Indonesia) use non standard date time format (dd/MM/yyyy), i modified the binding function with <code>"{0:dd/MM/yyyy}"</code> format.</p> <p>But, now the <strong>big problem</strong>, the modified binding function made the <code>CelenganEntityDataSource</code> cannot update while i try click the <code>LinkButton1</code> with <code>CommandName=Update</code>.</p> <p>Here the following errors message while i try to update:</p> <blockquote> <p>Error while setting property 'TanggalPemberian': 'Cannot convert the value of parameter 'TanggalPemberian' to the type 'System.DateTime'.'.</p> </blockquote> <p>Source Error :</p> <blockquote> <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below</p> </blockquote> <p>Stack Trace :</p> <pre><code>[EntityDataSourceValidationException: Error while setting property 'TanggalPemberian': 'Cannot convert the value of parameter 'TanggalPemberian' to the type 'System.DateTime'.'.] System.Web.UI.WebControls.EntityDataSourceView.ConvertProperties(IDictionary values, PropertyDescriptorCollection propertyDescriptors, ParameterCollection referenceParameters, Dictionary`2 convertedValues) +74592 System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +355 System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +87 System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1210 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +738 System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +88 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642610 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload