Solved

How do you delete a table in an access table in Vb.net

Posted on 2004-10-02
2
132 Views
Last Modified: 2010-04-23
I am using the following code already ,is the solution along these lines?

  Public Function IsTableInExistance(ByVal TableName As String) As Boolean
        Try
            conn.Open()
            Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                New Object() {Nothing, Nothing, Nothing, "TABLE"})
            TableName = TableName.ToUpper
            For Each row As DataRow In schemaTable.Rows
                Dim TblName As String = row(2)
                If TblName.ToUpper = TableName Then
                    Return True
                End If
            Next

        Catch Ex As Exception
            Throw New System.Exception("An exception has occurred. " & Ex.Message)
        Finally
            conn.Close()
        End Try
    End Function
0
Comment
Question by:visualbasic
2 Comments
 
LVL 3

Accepted Solution

by:
Arundel_Castle earned 50 total points
ID: 12207003
You don't need to do all that. Just issue a "Drop Table" SQL statment against the table you want removed. You can find the syntax for the drop statement in access help. Try it out first in the Query builder first. If you have records in there remember to delete them out first (if you are using relations between tables, otherwise you will get an error message about breaking the referential integrity) Use a "Delete * " SQL statment. If you have no parameters to pass place both statements as queries in access. You can then execute both of them with a OLEDB Command object. If you don't know what table it is your going to delete then use a prameter in both statements. This way you won't have to cycle throught the list of tables in your database. If the table doesn't exist you can also capture the error like you have above.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question