Hi, I'm getting this error below, when I try to update a field. I've got a table with a 'pagecontent' field with a type of text. I've got a FCKeditor in a formview.
Any ideas?
Thanks
Server Error in '/Build' Application.
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'.
Source Error:
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.
Yes this exception will come back from either the SQL you sent to the database or from the stored procedure you called.
My guess is you may be building out dynamic SQL or casting some type and the syntax is incorrect. If you are dynamically building TSQL in a stored proc, make sure the variable holding the SQL is large enough to build the entire statement.
You can also use a SQL trace if you are having trouble finding out the SQL being sent to the db from a stored proc containing parameters.
If the SQL is in code, just place a breakpoint where it is generated and run it manually against SQL server to see where the issue occurs.
ajw
Participant
768 Points
699 Posts
Incorrect syntax near 'nvarchar'.
Oct 23, 2009 04:10 PM|LINK
Hi, I'm getting this error below, when I try to update a field. I've got a table with a 'pagecontent' field with a type of text. I've got a FCKeditor in a formview.
Any ideas?
Thanks
Server Error in '/Build' Application.
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'.
Source Error:
Stack Trace:
SynergyNT
Participant
1641 Points
355 Posts
Re: Incorrect syntax near 'nvarchar'.
Oct 23, 2009 04:30 PM|LINK
Can you post your code, or at least the part mentioned? This unhandled exception error doesn't really help much.
atconway
All-Star
16846 Points
2756 Posts
Re: Incorrect syntax near 'nvarchar'.
Oct 23, 2009 04:31 PM|LINK
Yes this exception will come back from either the SQL you sent to the database or from the stored procedure you called.
My guess is you may be building out dynamic SQL or casting some type and the syntax is incorrect. If you are dynamically building TSQL in a stored proc, make sure the variable holding the SQL is large enough to build the entire statement.
You can also use a SQL trace if you are having trouble finding out the SQL being sent to the db from a stored proc containing parameters.
If the SQL is in code, just place a breakpoint where it is generated and run it manually against SQL server to see where the issue occurs.
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: Incorrect syntax near 'nvarchar'.
Oct 23, 2009 04:35 PM|LINK
Hi,
are trying to insert Info using Simple Insert Statement..
Just response.write sql statement and Chk if and Single Quote('),- Hypen(-) or any reseraved Character is passed while Inserting..
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
ajw
Participant
768 Points
699 Posts
Re: Incorrect syntax near 'nvarchar'.
Oct 23, 2009 07:00 PM|LINK
Hi here's the page code:
<%@ Page Language="VB" MasterPageFile="AdminMainMasterPage.master" AutoEventWireup="false"
CodeFile="edit-page.aspx.vb" Inherits="Admin_edit_page" Title="Untitled Page" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<h2>
Edit Page</h2>
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="PageID" DataSourceID="SqlDataSource1"
AllowPaging="True" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" DefaultMode="Edit" ForeColor="Black">
<FooterStyle BackColor="Tan" />
<EditItemTemplate>
Page Name:
<asp:TextBox ID="Page_NameTextBox" runat="server" Text='<%# Bind("[Page Name]") %>' />
<br />
PageContent:
<asp:TextBox ID="PageContentTextBox" runat="server" Text='' />
<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" BasePath="fckeditor/" Value='<%# Bind("PageContent") %>'
ToolbarSet="Basic" Height="100px" Width="100%">
</FCKeditorV2:FCKeditor>
<br />
<asp:TextBox ID="PageOrderTextBox" runat="server" Text='<%# Bind("PageOrder") %>' />
<br />
Section Heading:
<asp:TextBox ID="Section_HeadingTextBox" runat="server" Text='<%# Bind("[Section Heading]") %>' />
<br />
PageID:
<asp:Label ID="PageIDLabel1" runat="server" Text='<%# Eval("PageID") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Page Name:
<asp:TextBox ID="Page_NameTextBox" runat="server" Text='<%# Bind("[Page Name]") %>' />
<br />
PageContent:
<asp:TextBox ID="PageContentTextBox" runat="server" Text='<%# Bind("PageContent") %>' />
<br />
PageOrder:
<asp:TextBox ID="PageOrderTextBox" runat="server" Text='<%# Bind("PageOrder") %>' />
<br />
Section Heading:
<asp:TextBox ID="Section_HeadingTextBox" runat="server" Text='<%# Bind("[Section Heading]") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Page Name:
<asp:Label ID="Page_NameLabel" runat="server" Text='<%# Bind("[Page Name]") %>' />
<br />
PageContent:
<asp:Label ID="PageContentLabel" runat="server" Text='<%# Bind("PageContent") %>' />
<br />
PageOrder:
<asp:Label ID="PageOrderLabel" runat="server" Text='<%# Bind("PageOrder") %>' />
<br />
Section Heading:
<asp:Label ID="Section_HeadingLabel" runat="server" Text='<%# Bind("[Section Heading]") %>' />
<br />
PageID:
<asp:Label ID="PageIDLabel" runat="server" Text='<%# Eval("PageID") %>' />
<br />
</ItemTemplate>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:hallam-cmsConnectionString %>"
SelectCommand="SELECT Pages.PageName AS 'Page Name', Pages.PageContent, Pages.PageOrder, Sections.SectionHeading AS 'Section Heading', Pages.PageID FROM Pages INNER JOIN Sections ON Pages.SectionID = Sections.SectionID WHERE (Pages.PageID = @PageID)"
UpdateCommand="UPDATE Pages SET PageContent = @PageContent WHERE (PageID = @PageID)">
<SelectParameters>
<asp:QueryStringParameter Name="PageID" QueryStringField="PageID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="PageContent" Type="string" />
<asp:Parameter Name="PageID" />
</UpdateParameters>
</asp:SqlDataSource>
Insert FCKeditor here<br />
<br />
<br />
<br />
</asp:Content>
ajw
Participant
768 Points
699 Posts
Re: Incorrect syntax near 'nvarchar'.
Oct 24, 2009 10:56 AM|LINK
I put the SQL statements into Stored Procedures and that sorted the problem.
Andy