c# - Date fomat issue using UpdateCommand in ASP.NET -


i'm using asp.net (c#), mysql.

i'm trying use formview component feed sqldatasource ... goal create form handle data single table without coding , relying on framework as can.

i found how show data , edit them when come 'date' fields found stop in mission. since i'm italian use standard 'italian' date format (dd/mm/yyyy) that's quite different mysql internal date format (yyyy-mm-dd) lead date format error when try update fields.

the form include 'date' field defined way:

<asp:formview    id="_frmdata"    runat="server"    datakeynames="id"    datasourceid="_sdscontatto"    defaultmode="edit">    <edititemtemplate>         <asp:table runat="server">             <asp:tablerow>                 <asp:tablecell>                     <asp:textbox                          id="_txtdate"                         runat="server"                         text='<%#bind("date_field","{0:dd/mm/yyyy}")%>' />                  </asp:tablecell>              </asp:tablerow>         </asp:table>    </edititemtemplate> </asp:formview> 

the sqldatasource defined way:

<asp:sqldatasource id="_sdsdata                     runat="server"                    connectionstring="<%$ connectionstrings:data_db %>"                    providername="<%$ connectionstrings:data_db.providername %>"                    selectcommand=" select                                          date_field                                                                             table                                                                             id=@id;"                     updatecommand=" update                                          table                                    set                                          date_field = @date_value                                                                             id=@id;"> </asp:sqldatasource> 

using 'italian' date format lead error:

incorrect date value: '9/12/1971' column 'date_field' @ row 1

there's way fix type of problem ?

i tried mysql str_to_date() without luck.

best regards or suggestion.

mike

the solution relay 'separate' visualization data submission. cut short best way ovveride such problems one:

<asp:formview     id="_fvdata"     runat="server"     datakeynames="id"     datasourceid="_sdstable1"     defaultmode="insert" width="100%">     <insertitemtemplate>          <asp:textbox               id="_txtdate"               runat="server"               text='<%#eval("date_field","{0:dd/mm/yyyy}")%>' />     </insertitemtemplate> </asp:formview> 

in sqldatasource (either in insertparameters or updateparameters sections) need reference field trough controlparameter entry, in way:

<asp:sqldatasource      id="_sdstable1"      runat="server"     insertcommandtype="storedprocedure"     insertcommand="create_table1">     <insertparameters>          <asp:controlparameter                name="date_field"                convertemptystringtonull="true"                type="datetime"                controlid="_fvdata$_txtdate"                propertyname="text" />     </insertparameters> </asp:sqldatasource> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -