locked
SqlDataSource_InsertScores.Insert() -- Incorrect syntax RRS feed

  • Question

  • User1753528066 posted
    I am getting the following error and don't know how to fix it.
    Any help would be appricated
    Thanks
    John
     
    Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near ')'.
    
    Source Error: 
    
    
    Line 56:                 SqlDataSource_InsertScores.InsertParameters.Add("newDiff", LeagueID.ToString())
    Line 57: 
    Line 58:                 SqlDataSource_InsertScores.Insert()
    Line 59:                 SqlDataSource_InsertScore.InsertParameters.Clear()
    Line 60: 
     
      Dim SqlDataSource_InsertScores As SqlDataSource = SqlDataSource_InsertScore
                    SqlDataSource_InsertScores.InsertParameters.Add("RoundDate", RoundDate.ToString())
                    SqlDataSource_InsertScores.InsertParameters.Add("CourseID", CourseID.ToString())
                    SqlDataSource_InsertScores.InsertParameters.Add("PlayerID", PlayerIDint.ToString())
                    SqlDataSource_InsertScores.InsertParameters.Add("TBoxID", TBoxIDint.ToString())
                    SqlDataSource_InsertScores.InsertParameters.Add("Score", Scoreint.ToString())
                    SqlDataSource_InsertScores.InsertParameters.Add("LeagueID", LeagueID.ToString())
                    SqlDataSource_InsertScores.InsertParameters.Add("newDiff", LeagueID.ToString())
    
                    SqlDataSource_InsertScores.Insert()
                    SqlDataSource_InsertScore.InsertParameters.Clear()
    
                Else
                    SqlDataSource_InsertScore.InsertParameters.Clear()
    
                End If
            Next
    
     <asp:SqlDataSource ID="SqlDataSource_InsertScore" runat="server" ConnectionString="<%$ ConnectionStrings:New_ASPNET %>"
            DeleteCommand="DELETE FROM [Golf_League_Rounds] WHERE [LeagueRoundID] = @LeagueRoundID"
            InsertCommand="INSERT INTO Golf_League_Rounds(PlayerID, LeagueID, CourseID, TBoxID, RoundDate, Score, HandicapDifferential) VALUES (@PlayerID, @LeagueID, @CourseID, @TBoxID, @RoundDate, @Score,)"
            SelectCommand="SELECT * FROM [Golf_League_Rounds] WHERE ([LeagueID] = @LeagueID)"
            
            UpdateCommand="UPDATE Golf_League_Rounds SET PlayerID = @PlayerID, LeagueID = @LeagueID, CourseID = @CourseID, TBoxID = @TBoxID, RoundDate = @RoundDate, Score = @Score, HandicapDifferential = WHERE (LeagueRoundID = @LeagueRoundID)">
            <SelectParameters>
                <asp:Parameter DefaultValue="1" Name="LeagueID" Type="Int32" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="LeagueRoundID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="PlayerID" Type="Int32" />
                <asp:Parameter Name="LeagueID" Type="Int32" />
                <asp:Parameter Name="CourseID" Type="Int32" />
                <asp:Parameter Name="TBoxID" Type="Int32" />
                <asp:Parameter DbType="Date" Name="RoundDate" />
                <asp:Parameter Name="Score" Type="Int32" />
                <asp:Parameter Name="LeagueRoundID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                
            </InsertParameters>
        </asp:SqlDataSource>
    
    


     

     

    Friday, November 23, 2012 5:04 PM

Answers

  • User-821857111 posted

    The error message tells you that your insert command contains incorrect syntax.:

    "INSERT INTO Golf_League_Rounds(PlayerID, LeagueID, CourseID, TBoxID, RoundDate, Score, HandicapDifferential) VALUES (@PlayerID, @LeagueID, @CourseID, @TBoxID, @RoundDate, @Score,)"
           
    SelectCommand="SELECT * FROM [Golf_League_Rounds] WHERE ([LeagueID] = @LeagueID)"

    There's an extra , after @Score. That needs to be removed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 24, 2012 2:23 AM
  • User3866881 posted

    Hello

    john1506

    Besides what the MVP's idea, I think you don't need to dynamically add parameters but just define them directly in the aspx page until you you wanna define them dynamically.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 24, 2012 4:13 AM

All replies

  • User-821857111 posted

    The error message tells you that your insert command contains incorrect syntax.:

    "INSERT INTO Golf_League_Rounds(PlayerID, LeagueID, CourseID, TBoxID, RoundDate, Score, HandicapDifferential) VALUES (@PlayerID, @LeagueID, @CourseID, @TBoxID, @RoundDate, @Score,)"
           
    SelectCommand="SELECT * FROM [Golf_League_Rounds] WHERE ([LeagueID] = @LeagueID)"

    There's an extra , after @Score. That needs to be removed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 24, 2012 2:23 AM
  • User3866881 posted

    Hello

    john1506

    Besides what the MVP's idea, I think you don't need to dynamically add parameters but just define them directly in the aspx page until you you wanna define them dynamically.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 24, 2012 4:13 AM