473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to check if a table exists in Access XP

Hello,
I have a access application that resides locally on users desk, I
am writing a VB.Net interface that let's the users pull data down from
a SQL server database and populate the local access database with that
data, I need to check the local access database to see if there is
already a table with the name the users give. Anyone run into that or
have any idea how this would be done.

Thanks
Anthony
ta*******@tva.gov
Nov 20 '05 #1
3 14918
if u go to tools and option..and check to show the system tables, few more
tables will appear in your table list..this are the system tables.

one among this table stores all the name of the objects(including tables)..
u can query this table to check the existance of table.

Regards,
NetPointer

"Anthony Bowman" <ta******@comcast.net> wrote in message
news:da**************************@posting.google.c om...
Hello,
I have a access application that resides locally on users desk, I
am writing a VB.Net interface that let's the users pull data down from
a SQL server database and populate the local access database with that
data, I need to check the local access database to see if there is
already a table with the name the users give. Anyone run into that or
have any idea how this would be done.

Thanks
Anthony
ta*******@tva.gov

Nov 20 '05 #2
On 3 Nov 2003 14:09:24 -0800, ta******@comcast.net (Anthony Bowman) wrote:

¤ Hello,
¤ I have a access application that resides locally on users desk, I
¤ am writing a VB.Net interface that let's the users pull data down from
¤ a SQL server database and populate the local access database with that
¤ data, I need to check the local access database to see if there is
¤ already a table with the name the users give. Anyone run into that or
¤ have any idea how this would be done.
¤

Yes, you can use GetOleDbSchemaTable:

Dim AccessConnection As New System.Data.OleDb.OleDbConnection()
Dim SchemaTable As DataTable

AccessConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\My Documents\db1.mdb"
AccessConnection.Open()

'Retrieve schema information about Table1.
SchemaTable =
AccessConnection.GetOleDbSchemaTable(System.Data.O leDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, "Table1"})

If SchemaTable.Rows.Count <> 0 Then
Console.WriteLine("Table " & SchemaTable.Rows(0)!TABLE_NAME.ToString & " Exists")
Else
Console.WriteLine("Table does not exist")
End If

AccessConnection.Close()
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #3
Paul Clement <Us***********************@swspectrum.com> wrote in message news:<08********************************@4ax.com>. ..
On 3 Nov 2003 14:09:24 -0800, ta******@comcast.net (Anthony Bowman) wrote:

¤ Hello,
¤ I have a access application that resides locally on users desk, I
¤ am writing a VB.Net interface that let's the users pull data down from
¤ a SQL server database and populate the local access database with that
¤ data, I need to check the local access database to see if there is
¤ already a table with the name the users give. Anyone run into that or
¤ have any idea how this would be done.
¤

Yes, you can use GetOleDbSchemaTable:

Dim AccessConnection As New System.Data.OleDb.OleDbConnection()
Dim SchemaTable As DataTable

AccessConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\My Documents\db1.mdb"
AccessConnection.Open()

'Retrieve schema information about Table1.
SchemaTable =
AccessConnection.GetOleDbSchemaTable(System.Data.O leDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, "Table1"})

If SchemaTable.Rows.Count <> 0 Then
Console.WriteLine("Table " & SchemaTable.Rows(0)!TABLE_NAME.ToString & " Exists")
Else
Console.WriteLine("Table does not exist")
End If

AccessConnection.Close()
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)


Great - Both of the suggestions worked wonders and have fixed my
problem. I appreciate the help.

Thanks
Anthony
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an...
1
by: G G | last post by:
I need to check if a table exists in Access using ADO externally. I tried "Select Name from MSysObjects Where Name = 'myTable'" with the ADO command object, but I got an error than I don't...
10
by: Geoff Jones | last post by:
Hi I'm trying to drop a table by using: Dim cmd As New OleDbCommand("DROP TABLE IF EXISTS books", myconnection) cmd.ExecuteNonQuery() but I get a syntax error: "Syntax error in DROP TABLE...
9
by: Carl Fenley | last post by:
I am successfully adding stored procedures to an Access database. However, I need to be able to check if the stored procedure of the same name already exists. Is there a way to do this other...
5
by: Mike Charney | last post by:
I have an Access data project. In this project I have a form that when Access starts is loaded and this form has VBA code attached to it. One of the first things I need to do is check if a table...
2
by: RLN | last post by:
Re: Access 2003 I have code to check to see if a table exists. There are several other tables (tblQ12, tblQ13, etc) that do already exist & this code runs fine; msgbox says the value returned is...
6
by: BrianDP | last post by:
I have a table that has always been in my back-end of this application. The table is getting quite large, and, on top of that, we lose records out of this table. They just dissappear! No rhyme or...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
4
by: jaishu | last post by:
Hi all, I am in the process of developing a small Access application. i have the table locally in Access and I am using the following code to get the recordcount ( or to check if any record...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.