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. General Programming
  3. Visual Basic
  4. delete a whole table

delete a whole table

Scheduled Pinned Locked Moved Visual Basic
csharptutorial
9 Posts 5 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.
  • H Offline
    H Offline
    HRusaw
    wrote on last edited by
    #1

    I am trying to delete a whole table using vb.net oledbadapter, not individual records within the table. Does anyone have an example snipet of code to give me a clue. I can access the table and all the records, I just can't seem to pull off deleting the table. Thanks.

    C R S H 4 Replies Last reply
    0
    • H HRusaw

      I am trying to delete a whole table using vb.net oledbadapter, not individual records within the table. Does anyone have an example snipet of code to give me a clue. I can access the table and all the records, I just can't seem to pull off deleting the table. Thanks.

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      This is one of my favourite SQL commands.

      TRUNCATE TABLE <table-name>

      All your data disappears, but the table with all indexes and integrity constraints, is still there waiting for some inserts. Be aware however that the command requires administrative type priveleges and is not transactional. ie. you can't rollback if you want the data back. Use with caution. :) Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]

      H 1 Reply Last reply
      0
      • C Chris Meech

        This is one of my favourite SQL commands.

        TRUNCATE TABLE <table-name>

        All your data disappears, but the table with all indexes and integrity constraints, is still there waiting for some inserts. Be aware however that the command requires administrative type priveleges and is not transactional. ie. you can't rollback if you want the data back. Use with caution. :) Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]

        H Offline
        H Offline
        HRusaw
        wrote on last edited by
        #3

        Dim DS As New DataSet Dim query as string = "SELECT * from DAP" Dim OLEConn = New OleDb.OleDbConnection("connection string goes here") Dim adapter As New OleDb.OleDbDataAdapter adapter.SelectCommand = New OleDb.OleDbCommand(query, OLEConn) adapter.Fill(DS) THIS IS THE POINT OF TROUBLE... ???? DS.Tables().Clear() ???? 'not this ???? DS.Tables().Remove() ???? 'not this I want to delete the table "DAP" and I know the code above is not the correct way to just connect to a database, select a table, then delete the table. Does anyone have a snipet of code that 1. connect to a db. 2. selects a table. 3. deletes the selected table? Thanks.:)

        S 1 Reply Last reply
        0
        • H HRusaw

          Dim DS As New DataSet Dim query as string = "SELECT * from DAP" Dim OLEConn = New OleDb.OleDbConnection("connection string goes here") Dim adapter As New OleDb.OleDbDataAdapter adapter.SelectCommand = New OleDb.OleDbCommand(query, OLEConn) adapter.Fill(DS) THIS IS THE POINT OF TROUBLE... ???? DS.Tables().Clear() ???? 'not this ???? DS.Tables().Remove() ???? 'not this I want to delete the table "DAP" and I know the code above is not the correct way to just connect to a database, select a table, then delete the table. Does anyone have a snipet of code that 1. connect to a db. 2. selects a table. 3. deletes the selected table? Thanks.:)

          S Offline
          S Offline
          Scott Serl
          wrote on last edited by
          #4

          HRusaw wrote: Dim DS As New DataSet Dim query as string = "SELECT * from DAP" Dim OLEConn = New OleDb.OleDbConnection("connection string goes here") Dim adapter As New OleDb.OleDbDataAdapter adapter.SelectCommand = New OleDb.OleDbCommand(query, OLEConn) adapter.Fill(DS) Dim query as string = "TRUNCATE TABLE DAP" 'or if you need to log the action - but truncate will be faster 'Dim query as String = "DELETE FROM DAP" Dim OLEConn = New OleDb.OleDbConnection("connection string goes here") dim cmd as OleDbCommand = New OleDb.OleDbCommand(query, OLEConn) cmd.ExecuteNonQuery

          H 1 Reply Last reply
          0
          • H HRusaw

            I am trying to delete a whole table using vb.net oledbadapter, not individual records within the table. Does anyone have an example snipet of code to give me a clue. I can access the table and all the records, I just can't seem to pull off deleting the table. Thanks.

            R Offline
            R Offline
            rhenerlau
            wrote on last edited by
            #5

            in SQL (structured query language) there is a command that deletes the whole table: DROP Table (tablename) - I'm not sure the exact syntax of the VB.NET version of that command, but that should give you a place to start. Also you might check out the MSN group at http://groups.msn.com/VisualBasic/ (go to "Message Board" in the left frame and they have "Databases" and "VB.NET" message boards). You have to get a (free) msn passport in order to join the group, and then get approved by a manager or assistant manager (I am an assistant manager, so once you get the Passport, e-mail me @ rhenerlau@hotmail.com and I will approve you.) Hope this helps! Richard Henerlau

            1 Reply Last reply
            0
            • H HRusaw

              I am trying to delete a whole table using vb.net oledbadapter, not individual records within the table. Does anyone have an example snipet of code to give me a clue. I can access the table and all the records, I just can't seem to pull off deleting the table. Thanks.

              S Offline
              S Offline
              sumit21
              wrote on last edited by
              #6

              use oledbcommand //con is oledbconnection dim com as oledbcommand=new oledbcommand("drop table tablename",con) con.open com.executenonquery(); con.close hope this will work

              H 1 Reply Last reply
              0
              • H HRusaw

                I am trying to delete a whole table using vb.net oledbadapter, not individual records within the table. Does anyone have an example snipet of code to give me a clue. I can access the table and all the records, I just can't seem to pull off deleting the table. Thanks.

                H Offline
                H Offline
                HRusaw
                wrote on last edited by
                #7

                Scott and Sumit21, Thank you for your help. The snippet's you two submitted helped a lot and were exactly what I was looking for. Thanks Again, Helen :-D

                1 Reply Last reply
                0
                • S Scott Serl

                  HRusaw wrote: Dim DS As New DataSet Dim query as string = "SELECT * from DAP" Dim OLEConn = New OleDb.OleDbConnection("connection string goes here") Dim adapter As New OleDb.OleDbDataAdapter adapter.SelectCommand = New OleDb.OleDbCommand(query, OLEConn) adapter.Fill(DS) Dim query as string = "TRUNCATE TABLE DAP" 'or if you need to log the action - but truncate will be faster 'Dim query as String = "DELETE FROM DAP" Dim OLEConn = New OleDb.OleDbConnection("connection string goes here") dim cmd as OleDbCommand = New OleDb.OleDbCommand(query, OLEConn) cmd.ExecuteNonQuery

                  H Offline
                  H Offline
                  HRusaw
                  wrote on last edited by
                  #8

                  Scott and Sumit21, Thank you for your help. The snippet's you two submitted helped a lot and were exactly what I was looking for. Thanks Again, Helen :-D

                  1 Reply Last reply
                  0
                  • S sumit21

                    use oledbcommand //con is oledbconnection dim com as oledbcommand=new oledbcommand("drop table tablename",con) con.open com.executenonquery(); con.close hope this will work

                    H Offline
                    H Offline
                    HRusaw
                    wrote on last edited by
                    #9

                    Scott and Sumit21, Thank you for your help. The snippet's you two submitted helped a lot and were exactly what I was looking for. Thanks Again, Helen :-D

                    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