locked
Incorrect syntax near 'nvarchar'. Using FormView in asp.net RRS feed

  • Question

  • User-1070902567 posted

    I want to update data fromdatabase using FormView,

    Getting following error


    ERROR:

    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: Incorrect syntax near 'nvarchar'.

    Source Error:

    MYTABLE:

    USE [users]
    GO

    /****** Object: Table [dbo].[Payment5] Script Date: 11/07/2013 16:04:02 ******/
    SET ANSI_NULLS OFF
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE TABLE [dbo].[Payment5](
    [BusinessName] [nvarchar](500) NULL,
    [Address] [nvarchar](500) NULL,
    [Order date] [nvarchar](200) NULL,
    [Plan] [nvarchar](500) NULL,
    [NFC Tablets] [nvarchar](500) NULL,
    [First Payment] [nvarchar](500) NULL,
    [Due On] [nvarchar](500) NOT NULL,
    [Subsequent Monthly Payment] [nvarchar](500) NULL,
    [Due On Every Month] [nvarchar](500) NULL,
    [ClientId] [nvarchar](50) NULL,
    CONSTRAINT [PrimaryKey_1de9522e-ac4b-45b5-91e1-feaa4f4413de] PRIMARY KEY CLUSTERED
    (
    [Due On] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
    )

    GO

    ASPXPAGE CODE:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication9.WebForm3" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:stgdbConnectionString %>" DeleteCommand="DELETE FROM [Payment5] WHERE [Due On] = @Due_On" InsertCommand="INSERT INTO [Payment5] ([BusinessName], [Address], [Order date], [Plan], [NFC Tablets], [First Payment], [Due On], [Subsequent Monthly Payment], [Due On Every Month], [ClientId]) VALUES (@BusinessName, @Address, @Order_date, @Plan, @NFC_Tablets, @First_Payment, @Due_On, @Subsequent_Monthly_Payment, @Due_On_Every_Month, @ClientId)" SelectCommand="SELECT * FROM [Payment5]" UpdateCommand="UPDATE [Payment5] SET [BusinessName] = @BusinessName, [Address] = @Address, [Order date] = @Order_date, [Plan] = @Plan, [NFC Tablets] = @NFC_Tablets, [First Payment] = @First_Payment, [Subsequent Monthly Payment] = @Subsequent_Monthly_Payment, [Due On Every Month] = @Due_On_Every_Month, [ClientId] = @ClientId WHERE [Due On] = @Due_On">
    <DeleteParameters>
    <asp:Parameter Name="Due_On" Type="String" />
    </DeleteParameters>
    <InsertParameters>
    <asp:Parameter Name="BusinessName" Type="String" />
    <asp:Parameter Name="Address" Type="String" />
    <asp:Parameter Name="Order_date" Type="String" />
    <asp:Parameter Name="Plan" Type="String" />
    <asp:Parameter Name="NFC_Tablets" Type="String" />
    <asp:Parameter Name="First_Payment" Type="String" />
    <asp:Parameter Name="Due_On" Type="String" />
    <asp:Parameter Name="Subsequent_Monthly_Payment" Type="String" />
    <asp:Parameter Name="Due_On_Every_Month" Type="String" />
    <asp:Parameter Name="ClientId" Type="String" />
    </InsertParameters>
    <UpdateParameters>
    <asp:Parameter Name="BusinessName" Type="String" />
    <asp:Parameter Name="Address" Type="String" />
    <asp:Parameter Name="Order_date" Type="String" />
    <asp:Parameter Name="Plan" Type="String" />
    <asp:Parameter Name="NFC_Tablets" Type="String" />
    <asp:Parameter Name="First_Payment" Type="String" />
    <asp:Parameter Name="Subsequent_Monthly_Payment" Type="String" />
    <asp:Parameter Name="Due_On_Every_Month" Type="String" />
    <asp:Parameter Name="ClientId" Type="String" />
    <asp:Parameter Name="Due_On" Type="String" />
    </UpdateParameters>
    </asp:SqlDataSource>

    </div>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="Due On" DataSourceID="SqlDataSource1">
    <EditItemTemplate>
    BusinessName:
    <asp:TextBox ID="BusinessNameTextBox" runat="server" Text='<%# Bind("BusinessName") %>' />
    <br />
    Address:
    <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
    <br />
    Order date:
    <asp:TextBox ID="Order_dateTextBox" runat="server" Text='<%# Bind("[Order date]") %>' />
    <br />
    Plan:
    <asp:TextBox ID="PlanTextBox" runat="server" Text='<%# Bind("Plan") %>' />
    <br />
    NFC Tablets:
    <asp:TextBox ID="NFC_TabletsTextBox" runat="server" Text='<%# Bind("[NFC Tablets]") %>' />
    <br />
    First Payment:
    <asp:TextBox ID="First_PaymentTextBox" runat="server" Text='<%# Bind("[First Payment]") %>' />
    <br />
    Due On:
    <asp:Label ID="Due_OnLabel1" runat="server" Text='<%# Eval("[Due On]") %>' />
    <br />
    Subsequent Monthly Payment:
    <asp:TextBox ID="Subsequent_Monthly_PaymentTextBox" runat="server" Text='<%# Bind("[Subsequent Monthly Payment]") %>' />
    <br />
    Due On Every Month:
    <asp:TextBox ID="Due_On_Every_MonthTextBox" runat="server" Text='<%# Bind("[Due On Every Month]") %>' />
    <br />
    ClientId:
    <asp:TextBox ID="ClientIdTextBox" runat="server" Text='<%# Bind("ClientId") %>' />
    <br />
    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
    &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
    </EditItemTemplate>
    <InsertItemTemplate>
    BusinessName:
    <asp:TextBox ID="BusinessNameTextBox" runat="server" Text='<%# Bind("BusinessName") %>' />
    <br />
    Address:
    <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
    <br />
    Order date:
    <asp:TextBox ID="Order_dateTextBox" runat="server" Text='<%# Bind("[Order date]") %>' />
    <br />
    Plan:
    <asp:TextBox ID="PlanTextBox" runat="server" Text='<%# Bind("Plan") %>' />
    <br />
    NFC Tablets:
    <asp:TextBox ID="NFC_TabletsTextBox" runat="server" Text='<%# Bind("[NFC Tablets]") %>' />
    <br />
    First Payment:
    <asp:TextBox ID="First_PaymentTextBox" runat="server" Text='<%# Bind("[First Payment]") %>' />
    <br />
    Due On:
    <asp:TextBox ID="Due_OnTextBox" runat="server" Text='<%# Bind("[Due On]") %>' />
    <br />
    Subsequent Monthly Payment:
    <asp:TextBox ID="Subsequent_Monthly_PaymentTextBox" runat="server" Text='<%# Bind("[Subsequent Monthly Payment]") %>' />
    <br />
    Due On Every Month:
    <asp:TextBox ID="Due_On_Every_MonthTextBox" runat="server" Text='<%# Bind("[Due On Every Month]") %>' />
    <br />
    ClientId:
    <asp:TextBox ID="ClientIdTextBox" runat="server" Text='<%# Bind("ClientId") %>' />
    <br />
    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
    &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
    </InsertItemTemplate>
    <ItemTemplate>
    BusinessName:
    <asp:Label ID="BusinessNameLabel" runat="server" Text='<%# Bind("BusinessName") %>' />
    <br />
    Address:
    <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
    <br />
    Order date:
    <asp:Label ID="Order_dateLabel" runat="server" Text='<%# Bind("[Order date]") %>' />
    <br />
    Plan:
    <asp:Label ID="PlanLabel" runat="server" Text='<%# Bind("Plan") %>' />
    <br />
    NFC Tablets:
    <asp:Label ID="NFC_TabletsLabel" runat="server" Text='<%# Bind("[NFC Tablets]") %>' />
    <br />
    First Payment:
    <asp:Label ID="First_PaymentLabel" runat="server" Text='<%# Bind("[First Payment]") %>' />
    <br />
    Due On:
    <asp:Label ID="Due_OnLabel" runat="server" Text='<%# Eval("[Due On]") %>' />
    <br />
    Subsequent Monthly Payment:
    <asp:Label ID="Subsequent_Monthly_PaymentLabel" runat="server" Text='<%# Bind("[Subsequent Monthly Payment]") %>' />
    <br />
    Due On Every Month:
    <asp:Label ID="Due_On_Every_MonthLabel" runat="server" Text='<%# Bind("[Due On Every Month]") %>' />
    <br />
    ClientId:
    <asp:Label ID="ClientIdLabel" runat="server" Text='<%# Bind("ClientId") %>' />
    <br />
    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
    &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
    &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
    </ItemTemplate>
    </asp:FormView>
    </form>
    </body>
    </html>


    Thursday, November 7, 2013 5:38 AM

Answers

All replies

  • User724169276 posted

    remove the last comma ...instead of 

    [ClientId] [nvarchar](50) NULL,

    write

    [ClientId] [nvarchar](50) NULL

    Thursday, November 7, 2013 6:06 AM
  • User1079421601 posted

    Please try with this.

    CREATE TABLE [dbo].[Payment5](
    [BusinessName] [nvarchar](500) NULL,
    [Address] [nvarchar](500) NULL,
    [Order date] [nvarchar](200) NULL,
    [Plan] [nvarchar](500) NULL,
    [NFC Tablets] [nvarchar](500) NULL,
    [First Payment] [nvarchar](500) NULL,
    [Due On] [nvarchar](500) NOT NULL,
    [Subsequent Monthly Payment] [nvarchar](500) NULL,
    [Due On Every Month] [nvarchar](500) NULL,
    [ClientId] [nvarchar](50) NULL
    )

    Then add constraint and others.

    Thursday, November 7, 2013 6:17 AM
  • User-1070902567 posted

    Table was crteated successfully,

    When run the form data will display in Formview when i am update the data getting this error,

    I am using formview and sqldatasource control,
    When i am updating the data getting this error

    Thursday, November 7, 2013 6:27 AM
  • User503812343 posted

    change the column names and remove space from it

    for more information see below page

    http://support.microsoft.com/kb/264687/en-us

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 7, 2013 2:49 PM