Whats error in the bold line
-
Private Sub DeleteMultipleRecords(ByVal idCollection As StringCollection) 'Create sql Connection and Sql Command Dim con As New SqlConnection(strConnection) Dim cmd As New SqlCommand() Dim IDs As String = "" For Each id As String In idCollection IDs += id.ToString() & "," Next Try Dim test As String = IDs.Substring(0, IDs.LastIndexOf(",")) Dim sql As String = ("Delete from Categories" & " WHERE CategoryID in (") + test & ")" cmd.CommandType = CommandType.Text cmd.CommandText = sql cmd.Connection = con con.Open() cmd.ExecuteNonQuery() Catch ex As SqlException Dim errorMsg As String = "Error in Deletion" errorMsg += ex.Message Throw New Exception(errorMsg) Finally con.Close() End Try End Sub
-
Private Sub DeleteMultipleRecords(ByVal idCollection As StringCollection) 'Create sql Connection and Sql Command Dim con As New SqlConnection(strConnection) Dim cmd As New SqlCommand() Dim IDs As String = "" For Each id As String In idCollection IDs += id.ToString() & "," Next Try Dim test As String = IDs.Substring(0, IDs.LastIndexOf(",")) Dim sql As String = ("Delete from Categories" & " WHERE CategoryID in (") + test & ")" cmd.CommandType = CommandType.Text cmd.CommandText = sql cmd.Connection = con con.Open() cmd.ExecuteNonQuery() Catch ex As SqlException Dim errorMsg As String = "Error in Deletion" errorMsg += ex.Message Throw New Exception(errorMsg) Finally con.Close() End Try End Sub
KhandelwalA wrote:
Dim sql As String = ("Delete from Categories" & " WHERE CategoryID in (") + test & ")"
What error are you getting ? :zzz:
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article
-
Private Sub DeleteMultipleRecords(ByVal idCollection As StringCollection) 'Create sql Connection and Sql Command Dim con As New SqlConnection(strConnection) Dim cmd As New SqlCommand() Dim IDs As String = "" For Each id As String In idCollection IDs += id.ToString() & "," Next Try Dim test As String = IDs.Substring(0, IDs.LastIndexOf(",")) Dim sql As String = ("Delete from Categories" & " WHERE CategoryID in (") + test & ")" cmd.CommandType = CommandType.Text cmd.CommandText = sql cmd.Connection = con con.Open() cmd.ExecuteNonQuery() Catch ex As SqlException Dim errorMsg As String = "Error in Deletion" errorMsg += ex.Message Throw New Exception(errorMsg) Finally con.Close() End Try End Sub
-
Private Sub DeleteMultipleRecords(ByVal idCollection As StringCollection) 'Create sql Connection and Sql Command Dim con As New SqlConnection(strConnection) Dim cmd As New SqlCommand() Dim IDs As String = "" For Each id As String In idCollection IDs += id.ToString() & "," Next Try Dim test As String = IDs.Substring(0, IDs.LastIndexOf(",")) Dim sql As String = ("Delete from Categories" & " WHERE CategoryID in (") + test & ")" cmd.CommandType = CommandType.Text cmd.CommandText = sql cmd.Connection = con con.Open() cmd.ExecuteNonQuery() Catch ex As SqlException Dim errorMsg As String = "Error in Deletion" errorMsg += ex.Message Throw New Exception(errorMsg) Finally con.Close() End Try End Sub
Well, there's many errors here 1 - you asked in the wrong forum 2 - string mashing SQL is never wise 3 - you don't tell us why you think there's an error I would use the debugger in this situation to read the sql, then look at it and try it in the query analyser to work out what is wrong.
Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
-
KhandelwalA wrote:
Dim sql As String = ("Delete from Categories" & " WHERE CategoryID in (") + test & ")"
What error are you getting ? :zzz:
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article
When I selet a Single row through checkbox then error is :- Error in DeletionIncorrect syntax near ')'. When I selet a more than one row through checkbox then error is :- Error in DeletionIncorrect syntax near ','.