none
Conversion failed when converting datetime from character string. RRS feed

  • Question


  • I am using aspx C#. "Web pages"  I write code and working. But I reinstal flowing error occur.
    I reinstal windows, MS SQL, visual S.
    I don't understand microsoft idea. How can it be? Same code.
    Same region setting
    Is this problem solveble ?
    "I must use ODBC"

    [OdbcException (0x80131937): ERROR [22007] [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when converting datetime from character string.]
    System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) +35
    System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod) +1735
    System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader) +60
    System.Data.Odbc.OdbcCommand.ExecuteNonQuery() +87
    System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +401
    System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +721
    System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78
    System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1215
    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +858
    System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
    System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +117
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
    System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

    Thursday, January 24, 2008 1:02 PM

Answers

  • Visual Studio editor error. I found it . Paremeters order can not change with VS2005 "Order problem" It is change but still same previous.
    Friday, January 25, 2008 12:30 PM

All replies

  • Most likely your string value is not in a format suitable for a date conversion.  Check the string value.

     

    Gerry

    Thursday, January 24, 2008 1:27 PM
  • I use GridView. This means outomatic generation. I don't use code.
    I think windows religion setting problem some howSad.
    May be ms sql.
    But I can not solve until now:
    I am searchingSad



    grid part:
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
                BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
                DataSourceID="SqlDataSource1" OnRowDeleted="GridView1_RowDeleted1" Width="1000px" DataKeyNames="YetkilendirId,KULID,PLC_ID" Font-Names="Arial" Font-Size="Small" ForeColor="Black" GridLines="Vertical">
                <FooterStyle BackColor="#CCCC99" />
                <Columns>
                    <asp:TemplateField HeaderText="ID" SortExpression="PLC_ID">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("PLC_ID") %>' ToolTip="PLC ID"></asp:Label>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:Label ID="Label4" runat="server" Text="ID" ToolTip="PLC ID"></asp:Label>
                        </FooterTemplate>
                        <ItemStyle Width="30px" />
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("PLC_ID") %>' ToolTip="PLC ID"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="FIRMA_ADI" HeaderText="Firma" ReadOnly="True" SortExpression="FIRMA_ADI" />
                    <asp:BoundField DataField="FIRMA_YETKILISI" HeaderText="Yetkilisi" ReadOnly="True"
                        SortExpression="FIRMA_YETKILISI" >
                        <ItemStyle Width="100px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="BOLGE" HeaderText="BOLGE" SortExpression="BOLGE">
                        <ItemStyle Width="100px" />
                    </asp:BoundField>
                    <asp:TemplateField HeaderText="E" SortExpression="Ersim">
                        <EditItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Ersim") %>' ToolTip="Erişim Yetkisi" />
                        </EditItemTemplate>
                        <ItemStyle Width="20px" />
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Ersim") %>' Enabled="false"
                                ToolTip="Erişim Yetkisi" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="K" SortExpression="Konfig">
                        <EditItemTemplate>
                            <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("Konfig") %>' ToolTip="Pano Konfig Düzeltme İzni" />
                        </EditItemTemplate>
                        <ItemStyle Width="20px" />
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("Konfig") %>' Enabled="false" ToolTip="Pano Konfig Düzeltme İzni" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="TS" SortExpression="TankSev">
                        <EditItemTemplate>
                            <asp:CheckBox ID="CheckBox3" runat="server" Checked='<%# Bind("TankSev") %>' ToolTip="Pano Tank Seviye Değiştirme İzni" />
                        </EditItemTemplate>
                        <ItemStyle Width="20px" />
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox3" runat="server" Checked='<%# Bind("TankSev") %>' Enabled="false" ToolTip="Pano Tank Seviye Değiştirme İzni" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="BD" SortExpression="BolgeDol">
                        <EditItemTemplate>
                            <asp:CheckBox ID="CheckBox4" runat="server" Checked='<%# Bind("BolgeDol") %>' ToolTip="Pano Bölge Dolum İzni Verme Yetkisi" />
                        </EditItemTemplate>
                        <ItemStyle Width="20px" />
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox4" runat="server" Checked='<%# Bind("BolgeDol") %>' Enabled="false" ToolTip="Pano Bölge Dolum İzni Verme Yetkisi" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="D" SortExpression="Diger">
                        <EditItemTemplate>
                            <asp:CheckBox ID="CheckBox5" runat="server" Checked='<%# Bind("Diger") %>' ToolTip="Pano Diğer Yetkiler" />
                        </EditItemTemplate>
                        <ItemStyle Width="20px" />
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox5" runat="server" Checked='<%# Bind("Diger") %>' Enabled="false" ToolTip="Pano Diğer Yetkiler" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="YetkilendirId" HeaderText="Yetki Zaman" ReadOnly="True"
                        SortExpression="YetkilendirId" DataFormatString="{0:G}" >
                        <ItemStyle Width="80px" />
                    </asp:BoundField>
                    <asp:CommandField CancelText="İptal" DeleteText="Sil" EditText="D&#252;zelt" ShowDeleteButton="True"
                        ShowEditButton="True" UpdateText="G&#252;ncelle" ButtonType="Button" >
                        <ItemStyle Width="100px" />
                    </asp:CommandField>
                </Columns>
                <RowStyle BackColor="#F7F7DE" />
                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
                <EmptyDataTemplate>
                    <asp:Label ID="Label8" runat="server" Font-Names="Arial" Font-Size="Large" Text="Bir Kayıt Bulunamadı"></asp:Label>
                </EmptyDataTemplate>
            </asp:GridView>

    SQL Part

    <aspTongue TiedqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                DeleteCommand="DELETE FROM PANOYETKI WHERE (YetkilendirId = ?) and (KULID = ?) and (PLC_ID=?)" InsertCommand="INSERT INTO PANOYETKI (YetkilendirId, KULID, PLC_ID) VALUES (?, ?, ?)"
                ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT   PANOYETKI.YetkilendirId, PANOYETKI.KULID, PANOYETKI.PLC_ID, PANOYETKI.Ersim, &#13;&#10;                 PANOYETKI.Konfig, PANOYETKI.TankSev, PANOYETKI.BolgeDol, PANOYETKI.Diger, REHBER.FIRMA_ADI, REHBER.BOLGE, REHBER.FIRMA_YETKILISI, SEHIR.SEHIR&#13;&#10;FROM         PANOYETKI, REHBER, SEHIR&#13;&#10;WHERE     PANOYETKI.PLC_ID = REHBER.PLC_ID AND REHBER.TEL_KOD = SEHIR.TEL_KOD AND &#13;&#10;                      (PANOYETKI.KULID = ?) and ( REHBER.TEL_KOD=?)"
                UpdateCommand="UPDATE PANOYETKI SET Ersim = ?, Konfig = ?, TankSev = ?, BolgeDol = ?, Diger = ? WHERE  (YetkilendirId = ?) and (KULID = ?) and (PLC_ID=?)" OnUpdated="SqlDataSource1_Updated">
                <UpdateParameters>
                    <aspStick out tonguearameter Name="Ersim" Type="Boolean" />
                    <aspStick out tonguearameter Name="Konfig" Type="Boolean" />
                    <aspStick out tonguearameter Name="TankSev" Type="Boolean" />
                    <aspStick out tonguearameter Name="BolgeDol" Type="Boolean" />
                    <aspStick out tonguearameter Name="Diger" Type="Boolean" />
                    <aspStick out tonguearameter Name="YetkilendirId" Type="DateTime" />
                    <aspTongue TiedessionParameter Name="KULID" SessionField="YetkiUserID" Type="Int32" />
                    <aspStick out tonguearameter Name="PLC_ID" Type="Int32" />
                </UpdateParameters>
                <SelectParameters>
                    <aspTongue TiedessionParameter Name="KULID" SessionField="YetkiUserID" Type="Int32" />
                    <asp:ControlParameter ControlID="DropDownList1" Name="TEL_KOD" PropertyName="SelectedValue"
                        Type="String" />
                </SelectParameters>
                <InsertParameters>
                    <aspStick out tonguearameter Name="YetkilendirId" Type="DateTime" />
                    <aspTongue TiedessionParameter DefaultValue="KULID" Name="KULID" SessionField="YetkiUserID"
                        Type="Int32" />
                    <aspStick out tonguearameter Name="PLC_ID" Type="Int32" />
                </InsertParameters>
                <DeleteParameters>
                    <aspStick out tonguearameter Name="YetkilendirId" Type="DateTime" />
                    <aspTongue TiedessionParameter Name="KULID " SessionField="YetkiUserID" Type="Int32" />
                    <aspStick out tonguearameter Name="PLC_ID" Type="Int32" />
                </DeleteParameters>
            </aspTongue TiedqlDataSource>
    Thursday, January 24, 2008 1:36 PM
  • You should be able to see what values are going into your Update query in SQL.  Run a trace (SQL Profiler) and look at the values going into your Update query.  Most likely the format of the string value (or datetime field) is not correctly formatted.

     

    Gerry

    Thursday, January 24, 2008 1:44 PM
  • You are right string wrong

    exec sp_executesql N'UPDATE PANOYETKI SET Ersim = @P1, Konfig = @P2, TankSev = @P3, BolgeDol = @P4, Diger = @P5 WHERE  (YetkilendirId =
    @P6) and (KULID = @P7) and (PLC_ID=@P8)',N'@P1 bit,@P2 bit,@P3 bit,@P4 bit,@P5 bit,@P6 nvarchar(2),@P7 datetime,@P8
    int',1,0,1,1,1,N'6',''2008-01-24 12:05:38:000'',3


    milisecond I think Or I know {ts'2008-01-24 12:05:38'} in normal SQL. How can solve? any Idea?


    I found
    exec sp_executesql N'UPDATE PANOYETKI SET Ersim = @P1, Konfig = @P2, TankSev = @P3, BolgeDol = @P4, Diger = @P5 WHERE 
    (YetkilendirId = @P6) and (KULID = @P7) and (PLC_ID=@P8)',N'@P1 bit,@P2 bit,@P3 bit,@P4 bit,@P5 bit,@P6 nvarchar(2),@P7 datetime,@P8
    int',1,0,0,0,0,N'6',''2008-01-24 12:05:38:000'',3

    Msg 102, Level 15, State 1, Line 3
    Incorrect syntax near '2008'.

    But Gridview generate How can I handle ?
    Thursday, January 24, 2008 1:57 PM
  • I think you are getting "Incorrect syntax near '2008'" because your datetime appears to have two 's around it

     

    ' ' 2008-01-24 12:05:38:000 ' ' instead of just one '

     

    '2008-01-24 12:05:38:000'

     

    At least I can re-produce your error with the above.

     

    Gerry

    Thursday, January 24, 2008 2:10 PM
  • This is result.
    Msg 241, Level 16, State 1, Line 2
    Conversion failed when converting datetime from character string.
    I know SQL. It shoul be like that {ts'2008-01-24 12:05:38:000} .
    But How can I change grid generation. I use alot of date time different page.


    Working I use code only one part
    trace log Like that.
    UPDATE KULLANICI SET ulog_tarih ={ts'2008-01-24 16:23:49'}, ulog_count =0  WHERE     (KULID =2)
    and It is working.

    Did any one know how to change grid SQL generation c# aspx
    or
    how to change setting for MSSQL "
    '2008-01-24 16:23:49'" accept this.

    My previous instalation I think accept '2008-01-24 16:23:49' for date time. But I don't know how. I use regional setting and Database properties.  Big question Why  do dat.net use same setting?

    Thursday, January 24, 2008 2:14 PM
  • Visual Studio editor error. I found it . Paremeters order can not change with VS2005 "Order problem" It is change but still same previous.
    Friday, January 25, 2008 12:30 PM