cannot get my gridview to delete rows.

Posted on 2009-02-09
Last Modified: 2012-08-14
I am using the gridiews built in delete command, to delete a row in my gridview but I get the following error.
I am passing the results through a webservice that is called when the delete button is pressed.
But i get the following error.
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Incorrect syntax near ','.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at WAB_DataAccess.delaColleagueDetails(String strConn, Int32 intColleagueID, String strColleagueName, String strMobile, String strExtension)
at WAB_DataAccessWS.delColleaguedetails(String strConn, Int32 ColleagueID, String ColleagueName, String Mobile, String Extension)
--- End of inner exception stack trace ---

my webservice & class.

    'Delete method called from the webservice

    Public Shared Function delaColleagueDetails(ByVal strConn As String, ByVal intColleagueID As Integer, ByVal strColleagueName As String, ByVal strMobile As String, ByVal strExtension As String) As Integer

        Dim conn As SqlConnection = New SqlConnection(strConn)

        Dim cmd As SqlCommand = New SqlCommand("exec p_DeleteColleagueDetails '" & intColleagueID & "', '" & strColleagueName & "', " & strMobile & ", '" & strExtension & "'", conn)

        Dim result As Integer = 0


        result = cmd.ExecuteNonQuery()


        Return result

    End Function

    'Delete method

    <WebMethod()> _

    Public Function delColleaguedetails(ByVal strConn As String, ByVal ColleagueID As Integer, ByVal ColleagueName As String, ByVal Mobile As String, ByVal Extension As String) As Integer

        Return WAB_DataAccess.delaColleagueDetails(strConn, ColleagueID, ColleagueName, Mobile, Extension)

    End Function 


<asp:objectdatasource id="objdsColleagueDetails" runat="server" Typename="WAB_DataAccessWS.WAB_DataAccessWS" SelectMethod="selColleagueDetails"

                                            UpdateMethod="updColleagueDetails" DeleteMethod="delColleagueDetails">


                        <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn"  Propertyname="Value" Type="String" />

                        <asp:ControlParameter ControlID="ddlDepartment" Name="intDepartmentID" PropertyName="SelectedValue" Type="Int32" />



                        <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn" Propertyname="Value" Type="String" />

                        <asp:Parameter Name="ColleagueID" Type="Int32" />

                        <asp:Parameter Name="ColleagueName" Type="String" />

                        <asp:Parameter Name="Mobile" Type="String" />

                        <asp:Parameter Name="Extension" Type="String" />



                        <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn" Propertyname="Value" Type="String" />

                        <asp:Parameter Name="ColleagueID" Type="Int32" />

                        <asp:Parameter Name="ColleagueName" Type="String" />

                        <asp:Parameter Name="Mobile" Type="String" />

                        <asp:Parameter Name="Extension" Type="String" />



Open in new window

Question by:aneilg
    LVL 15

    Expert Comment

    by:Praveen Venu
    can u please post the ptocedure


    Author Comment

    thanks for your help.

    ColleagueID            int
    ColleagueName      nvarchar(50)
    Mobile                  nvarchar(50)
    Extension            nvarchar(50)

    DepartmentID            int
    DepartmentName      nvarchar(50)

    CollDepID            int
    ColleagueID            nvarchar(50)
    DepartmentID            nvarchar(50)


    i am displaying the information in a gridview as follows.

    colleagueID  colleaguename  mobile  extension
    1                   fred                   0112    0113
    2                   mary                 0114     0222

    CREATE PROCEDURE [dbo].[p_DeleteColleagueDetails]
    @ColleagueID int,
    @ColleagueName varchar(50),
    @Mobile varchar(25),
    @Extension varchar(25)
    DELETE FROM t_ColleagueDepartment
    WHERE ColleagueID = @ColleagueID
    DELETE FROM t_ColleagueDetails
    WHERE ColleagueID = @ColleagueID
            AND ColleagueName = @ColleagueName
            AND Mobile = @Mobile
            AND Extension = @Extension

    LVL 15

    Expert Comment

    by:Praveen Venu
    can u please add a watch to see what is the final sql string in the



    Author Comment

    thanks for that,
    i've tried debugging it but i get WAB_DataAccess.delaColleagueDetails is not declared or the module containing it is not loaded in the debuggibg session.

    LVL 15

    Accepted Solution

    Can you please tell me

    Do you have any problem for deleting all the rows or is it for a particular  row.

    If it is a particular row then if there any apostrophe in that row?

    Author Comment

    good point,
    i've tried it on all the rows but still get the error.

    any more ideas.

    i cannot see anything that stands out.

    LVL 15

    Expert Comment

    by:Praveen Venu
    is it solved?
    LVL 15

    Expert Comment

    by:Praveen Venu

    Author Comment

    Hi thanks for your help.

    it's sort of solved.

    I am using the built in edit, can, delete buttons.

    When i click on edit button the gridview changes the columns to textboxes, so it enables my template fields.
    I have an update button here, but when i changed it to delete it worked.

    Currently when i add a delete button it puts it along side the edit button, so it was not binding to the gridview.

    I just need to figure out how to add a delete button besides the update & cancel buton when i press the edit button.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    This video is a brief demonstration on how to use security groups and Network Access Control Lists (ACLs) in Amazon Web Services.  Security groups and Network ACLs are mechanisms you can use in AWS to control network traffic.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now