简体   繁体   中英

SqlException (0x80131904): Incorrect syntax near '?'

I am new to SQl and I'm running off of examples and I am wondering if anyone can help with a section of code that I have. I understand that there is a syntax error with one of my question marks but I can't figure out where it is or why it is happening for that matter.

Here is my code:

-

    <br />
    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Overline="True" 
        Font-Size="X-Large" Font-Underline="True" Text="Product Information Log"></asp:Label>
    <br />
    <br />

</div>
<asp:GridView ID="GridView1" runat="server" 
    AllowSorting="True" AutoGenerateColumns="False" BackColor="White" 
    BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
    DataSourceID="SqlDataSource1" 
    EmptyDataText="There are no data records to display." ForeColor="Black" 
    GridLines="Vertical">
    <AlternatingRowStyle BackColor="#808080" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="CICNumber" HeaderText="CICNumber" 
            SortExpression="CICNumber" />
        <asp:BoundField DataField="ItemName" HeaderText="ItemName" 
            SortExpression="ItemName" />
        <asp:BoundField DataField="ItemNumber" HeaderText="ItemNumber" 
            SortExpression="ItemNumber" />
        <asp:BoundField DataField="PLUNumber" HeaderText="PLUNumber" 
            SortExpression="PLUNumber" />
        <asp:BoundField DataField="PackSize" HeaderText="PackSize" 
            SortExpression="PackSize" />
        <asp:BoundField DataField="CaseCost" HeaderText="CaseCost" 
            SortExpression="CaseCost" />
        <asp:BoundField DataField="UnitRetailCost" HeaderText="UnitRetailCost" 
            SortExpression="UnitRetailCost" />
            <asp:CommandField ShowDeleteButton="true" />
            <asp:CommandField ShowEditButton="true" />

    </Columns>
    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="Green" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 

    ConnectionString="<%$ ConnectionStrings:ProductInfoConnectionString1 %>" 
    DeleteCommand="DELETE FROM [tblProductInfo] WHERE [UserID] = ?" 
    InsertCommand="INSERT INTO [tblProductInfo] ([CICNumber], [ItemName], [ItemNumber], [PLUNumber], [PackSize], [CaseCost], [UnitRetailCost]) VALUES (?, ?, ?, ?, ?, ?, ?)"
    ProviderName="<%$ ConnectionStrings:ProductInfoConnectionString1.ProviderName %>" 
    SelectCommand="SELECT [CICNumber], [ItemName], [ItemNumber], [PLUNumber], [PackSize], [CaseCost], [UnitRetailCost] FROM [tblProductInfo]"
    UpdateCommand="UPDATE [tblProductInfo] SET [ItemName] = ?, [ItemNumber] = ?, [PLUNumber] = ?, [PackSize] = ?, [CaseCost] = ?, [UnitRetailCost] = ?, WHERE [CICNumber] = ?">


    <DeleteParameters>
                <asp:Parameter Name="CICNumber" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="ItemName" Type="String" />
                <asp:Parameter Name="ItemNumber" Type="Int32" />
                <asp:Parameter Name="PLUNumber" Type="Int32" />
                <asp:Parameter Name="PackSize" Type="String" />
                <asp:Parameter Name="CaseCost" Type="Int32" />
                <asp:Parameter Name="UnitRetailCost" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="CICNumber" Type="Int32" />
                <asp:Parameter Name="ItemName" Type="String" />
                <asp:Parameter Name="ItemNumber" Type="Int32" />
                <asp:Parameter Name="PLUNumber" Type="Int32" />
                <asp:Parameter Name="PackSize" Type="String" />
                <asp:Parameter Name="CaseCost" Type="Int32" />
                <asp:Parameter Name="UnitRetailCost" Type="Int32" />
            </InsertParameters>

</asp:SqlDataSource>
</form>

You have

[UnitRetailCost] = ?, WHERE [CICNumber] = ?

at the end of the update statement, the comma needs to be removed:

[UnitRetailCost] = ? WHERE [CICNumber] = ?

In my case, there was just an unprintable character in the script that didn't show up in Visual-Studio, but is visible in bitbucket-source-viewer:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM