Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Whats error in the bold line

Whats error in the bold line

Scheduled Pinned Locked Moved ASP.NET
databasehelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KhandelwalA
    wrote on last edited by
    #1

    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

    A A C 3 Replies Last reply
    0
    • K KhandelwalA

      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

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • K KhandelwalA

        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

        A Offline
        A Offline
        Amol 111
        wrote on last edited by
        #3

        Dim sql As String = ("Delete from Categories WHERE CategoryID in (" & +test & ")")

        1 Reply Last reply
        0
        • K KhandelwalA

          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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • A Abhijit Jana

            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

            K Offline
            K Offline
            KhandelwalA
            wrote on last edited by
            #5

            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 ','.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups