cannot get my gridview to delete rows.

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

Who is Participating?
Praveen VenuTechnical Project ManagerCommented:
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?
Praveen VenuTechnical Project ManagerCommented:
can u please post the ptocedure

aneilgAuthor Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Praveen VenuTechnical Project ManagerCommented:
can u please add a watch to see what is the final sql string in the


aneilgAuthor Commented:
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.

aneilgAuthor Commented:
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.

Praveen VenuTechnical Project ManagerCommented:
is it solved?
aneilgAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.