Monday, March 26, 2012

Incorrect syntax near 'nvarchar'

When I try to insert data in sql server 2000 database with a formview. I got this error:

Line 1: Incorrect syntax near 'nvarchar'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'nvarchar'.

The insert statement is right and works manuallly.

INSERT INTO REUNIOES(DATA_P1, DATA_P2, [MIG/SIR], FRENTE, LIDER, ATIVIDADE, DATA_PLANEJADO, DATA_CONCLUSAO, DATA_REPLANEJAMENTO, STATUS, EQUIPE) VALUES (@.DATA_P1, @.DATA_P2, @.MIG, @.FRENTE, @.LIDER, @.ATIVIDADE, @.DATA_PLANEJADO, @.DATA_CONCLUSAO, @.DATA_REPLANEJAMENTO, @.STATUS, @.EQUIPE)

Please, help me with this thread.

You will probably have to show something of your other code as this is not sufficient anough to track down the error. If you have profiler, let a trace run during the manipulation within the control to see what wrong commad is executed against the SQl Server database.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||

The code:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Teste.aspx.vb" Inherits="Teste" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1"

DefaultMode="Insert">

<EditItemTemplate>

DATA_P1:

<asp:TextBox ID="DATA_P1TextBox" runat="server" Text='<%# Bind("DATA_P1") %>'></asp:TextBox><br />

DATA_P2:

<asp:TextBox ID="DATA_P2TextBox" runat="server" Text='<%# Bind("DATA_P2") %>'></asp:TextBox><br />

MIG/SIR:

<asp:TextBox ID="MIG_SIRTextBox" runat="server" Text='<%# Bind("[MIG/SIR]") %>'></asp:TextBox><br />

FRENTE:

<asp:TextBox ID="FRENTETextBox" runat="server" Text='<%# Bind("FRENTE") %>'></asp:TextBox><br />

LIDER:

<asp:TextBox ID="LIDERTextBox" runat="server" Text='<%# Bind("LIDER") %>'></asp:TextBox><br />

ATIVIDADE:

<asp:TextBox ID="ATIVIDADETextBox" runat="server" Text='<%# Bind("ATIVIDADE") %>'></asp:TextBox><br />

DATA_PLANEJADO:

<asp:TextBox ID="DATA_PLANEJADOTextBox" runat="server" Text='<%# Bind("DATA_PLANEJADO") %>'></asp:TextBox><br />

DATA_CONCLUSAO:

<asp:TextBox ID="DATA_CONCLUSAOTextBox" runat="server" Text='<%# Bind("DATA_CONCLUSAO") %>'></asp:TextBox><br />

DATA_REPLANEJAMENTO:

<asp:TextBox ID="DATA_REPLANEJAMENTOTextBox" runat="server" Text='<%# Bind("DATA_REPLANEJAMENTO") %>'></asp:TextBox><br />

STATUS:

<asp:TextBox ID="STATUSTextBox" runat="server" Text='<%# Bind("STATUS") %>'></asp:TextBox><br />

EQUIPE:

<asp:TextBox ID="EQUIPETextBox" runat="server" Text='<%# Bind("EQUIPE") %>'></asp:TextBox><br />

ID:

<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />

<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"

Text="Update"></asp:LinkButton>

<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

Text="Cancel"></asp:LinkButton>

</EditItemTemplate>

<InsertItemTemplate>

DATA_P1:

<asp:TextBox ID="DATA_P1TextBox" runat="server" Text='<%# Bind("DATA_P1") %>'></asp:TextBox><br />

DATA_P2:

<asp:TextBox ID="DATA_P2TextBox" runat="server" Text='<%# Bind("DATA_P2") %>'></asp:TextBox><br />

MIG/SIR:

<asp:TextBox ID="MIG_SIRTextBox" runat="server" Text='<%# Bind("[MIG/SIR]") %>'></asp:TextBox><br />

FRENTE:

<asp:TextBox ID="FRENTETextBox" runat="server" Text='<%# Bind("FRENTE") %>'></asp:TextBox><br />

LIDER:

<asp:TextBox ID="LIDERTextBox" runat="server" Text='<%# Bind("LIDER") %>'></asp:TextBox><br />

ATIVIDADE:

<asp:TextBox ID="ATIVIDADETextBox" runat="server" Text='<%# Bind("ATIVIDADE") %>'></asp:TextBox><br />

DATA_PLANEJADO:

<asp:TextBox ID="DATA_PLANEJADOTextBox" runat="server" Text='<%# Bind("DATA_PLANEJADO") %>'></asp:TextBox><br />

DATA_CONCLUSAO:

<asp:TextBox ID="DATA_CONCLUSAOTextBox" runat="server" Text='<%# Bind("DATA_CONCLUSAO") %>'></asp:TextBox><br />

DATA_REPLANEJAMENTO:

<asp:TextBox ID="DATA_REPLANEJAMENTOTextBox" runat="server" Text='<%# Bind("DATA_REPLANEJAMENTO") %>'></asp:TextBox><br />

STATUS:

<asp:TextBox ID="STATUSTextBox" runat="server" Text='<%# Bind("STATUS") %>'></asp:TextBox><br />

EQUIPE:

<asp:TextBox ID="EQUIPETextBox" runat="server" Text='<%# Bind("EQUIPE") %>'></asp:TextBox><br />

<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"

Text="Insert"></asp:LinkButton>

<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

Text="Cancel"></asp:LinkButton>

</InsertItemTemplate>

<ItemTemplate>

DATA_P1:

<asp:Label ID="DATA_P1Label" runat="server" Text='<%# Bind("DATA_P1") %>'></asp:Label><br />

DATA_P2:

<asp:Label ID="DATA_P2Label" runat="server" Text='<%# Bind("DATA_P2") %>'></asp:Label><br />

MIG/SIR:

<asp:Label ID="MIG_SIRLabel" runat="server" Text='<%# Bind("[MIG/SIR]") %>'></asp:Label><br />

FRENTE:

<asp:Label ID="FRENTELabel" runat="server" Text='<%# Bind("FRENTE") %>'></asp:Label><br />

LIDER:

<asp:Label ID="LIDERLabel" runat="server" Text='<%# Bind("LIDER") %>'></asp:Label><br />

ATIVIDADE:

<asp:Label ID="ATIVIDADELabel" runat="server" Text='<%# Bind("ATIVIDADE") %>'></asp:Label><br />

DATA_PLANEJADO:

<asp:Label ID="DATA_PLANEJADOLabel" runat="server" Text='<%# Bind("DATA_PLANEJADO") %>'></asp:Label><br />

DATA_CONCLUSAO:

<asp:Label ID="DATA_CONCLUSAOLabel" runat="server" Text='<%# Bind("DATA_CONCLUSAO") %>'></asp:Label><br />

DATA_REPLANEJAMENTO:

<asp:Label ID="DATA_REPLANEJAMENTOLabel" runat="server" Text='<%# Bind("DATA_REPLANEJAMENTO") %>'></asp:Label><br />

STATUS:

<asp:Label ID="STATUSLabel" runat="server" Text='<%# Bind("STATUS") %>'></asp:Label><br />

EQUIPE:

<asp:Label ID="EQUIPELabel" runat="server" Text='<%# Bind("EQUIPE") %>'></asp:Label><br />

ID:

<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />

<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"

Text="New"></asp:LinkButton>

</ItemTemplate>

</asp:FormView>

&nbsp;</div>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GD_CONN2 %>"

InsertCommand="INSERT INTO REUNIOES(DATA_P1, DATA_P2, [MIG/SIR], FRENTE, LIDER, ATIVIDADE, DATA_PLANEJADO, DATA_CONCLUSAO, DATA_REPLANEJAMENTO, STATUS, EQUIPE) VALUES&#13;&#10;( CONVERT (DATETIME, @.DATA_P1, 103),&#13;&#10;CONVERT (DATETIME, @.DATA_P2, 103),&#13;&#10;@.MIG, &#13;&#10;@.FRENTE, &#13;&#10;@.LIDER,&#13;&#10;@.ATIVIDADE,&#13;&#10; CONVERT (DATETIME, @.DATA_PLANEJADO, 103),&#13;&#10; CONVERT (DATETIME, @.DATACONCLUSAO, 103),&#13;&#10; CONVERT (DATETIME, @.DATA_REPLANEJAMENTO, 103),&#13;&#10;@.STATUS, &#13;&#10;@.EQUIPE)" SelectCommand="SELECT * FROM [REUNIOES] where id=@.id" CancelSelectOnNullParameter="False" EnableCaching="True">

<InsertParameters>

<asp:Parameter Name="DATA_P1" />

<asp:Parameter Name="DATA_P2" />

<asp:Parameter Name="MIG" />

<asp:Parameter Name="FRENTE" />

<asp:Parameter Name="LIDER" />

<asp:Parameter Name="ATIVIDADE" />

<asp:Parameter Name="DATA_PLANEJADO" />

<asp:Parameter Name="DATACONCLUSAO" />

<asp:Parameter Name="DATA_REPLANEJAMENTO" />

<asp:Parameter Name="STATUS" />

<asp:Parameter Name="EQUIPE" />

</InsertParameters>

<SelectParameters>

<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Decimal" />

</SelectParameters>

</asp:SqlDataSource>

&nbsp;

</form>

</body>

</html>

Thanks, Jens.

|||Hi,

could that be that there is a trigger on the table you are inserting to which is cuasing the syntax error ? I can′t see any problems in the statement you posted here. Did you start the profiler to see which commands are executed against the database ?

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

I remember that was a function I′ve create to validate datetime. I′m analyzing ....

.

About the profiler. How can I start it? I never used it before.

|||Its located in the program folder (Start > Programs >...) the SQL Server profiler can trace exected statements as well as server events like exceptions etc. I will help you to investigate which command is finally executed against the database.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

The solution was create a new page with same configuration... :P

Thanks, Jens.

No comments:

Post a Comment