We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Clear content of table in a MDB

MichMat
MichMat asked
on
Medium Priority
185 Views
Last Modified: 2012-05-06
Hi

Im trying to delete the data in a table in MDB , I call the data into a dataset then clear the dataset and save changes ....... this does not seam to work

Any ideas ?
Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
You don't need to do that. You just have to create a connection to the database and execute a OledbCommand to clear all the information with a T-SQL like "DELETE * FROM myTable"
 Here you have an example of the OledbCommand
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.executenonquery.aspx 

Author

Commented:
I cant seam to get this code to work it throws up no errors and it does nothing
its the same code that saves to the file shouldnt that work the same way ?
 Sub DeleteMeetingsData()
 
        Dim oCommT As OleDbCommand
        Dim oDataT As OleDbDataAdapter
        Dim ConnectT, oMainQueryT As String
 
        Dim OleConnT As OleDbConnection
 
            ConnectT = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppPath & "\Import.mdb;User ID=Admin;Password="
            oMainQueryT = "DELETE * FROM Meetings"
 
            OleConnT = New OleDbConnection(ConnectT)
            oCommT = New OleDbCommand(oMainQueryT, OleConnT)
            oDataT = New OleDbDataAdapter(oMainQueryT, OleConnT)
            Dim cbT As OleDbCommandBuilder = New OleDbCommandBuilder(oDataT)
            OleConnT.Close()
    End Sub

Open in new window

IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
You don't need to use OleDbDataAdapter or OleDbCommandBuilder.
This should be enough

    Using connection As New OleDbConnection(ConnectT)
        connection.Open()
        Dim command As New OleDbCommand(oMainQueryT, connection)
        command.ExecuteNonQuery()
    End Using

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Yes, you are right :) that works perfectly. Thank you so much for your help.
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Glad I could help
jpaulino
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.