• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

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
 
        conn.Open()
        result = cmd.ExecuteNonQuery()
 
        conn.Close()
 
        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 
 
mygridview
<asp:objectdatasource id="objdsColleagueDetails" runat="server" Typename="WAB_DataAccessWS.WAB_DataAccessWS" SelectMethod="selColleagueDetails"
 
                                            UpdateMethod="updColleagueDetails" DeleteMethod="delColleagueDetails">
                    <selectparameters>
                        <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn"  Propertyname="Value" Type="String" />
 
                        <asp:ControlParameter ControlID="ddlDepartment" Name="intDepartmentID" PropertyName="SelectedValue" Type="Int32" />
 
                    </selectparameters>
                    <UpdateParameters>
                        <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" />
                    </UpdateParameters>
                    <DeleteParameters>
                        <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" />
                    </DeleteParameters>
                </asp:objectdatasource>

Open in new window

0
aneilg
Asked:
aneilg
  • 5
  • 4
1 Solution
 
Praveen VenuCommented:
can u please post the ptocedure
delColleagueDetails

0
 
aneilgAuthor Commented:
thanks for your help.

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

t_DepartmentDetails
DepartmentID            int
DepartmentName      nvarchar(50)

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

FK_t_ColleagueDepartment_t_ColleagueDetails
FK_t_ColleagueDepartment_t_DepartmentDetails

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)
AS
DELETE FROM t_ColleagueDepartment
WHERE ColleagueID = @ColleagueID
DELETE FROM t_ColleagueDetails
WHERE ColleagueID = @ColleagueID
        AND ColleagueName = @ColleagueName
        AND Mobile = @Mobile
        AND Extension = @Extension

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

WAB_DataAccess.delaColleagueDetails


0
Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

 
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.

0
 
Praveen VenuCommented:
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?
0
 
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.

thanks.
0
 
Praveen VenuCommented:
is it solved?
0
 
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.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now