delete a whole table
-
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.
-
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.
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]
-
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]
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.:)
-
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.:)
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
-
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.
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
-
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.
-
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.
-
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
-
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