Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old September 29th, 2003, 11:18 AM
asnavale asnavale is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: India
Posts: 5 asnavale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
VB programming for database application

I am developing a program in VB5 to work with an MS Access database. I have written code for to check if the file exists and to create the database file if it does not exist. Now I have a problem to solve.

The database contains several related tables. Some tables are created at the time of creating the database. Some tables have to be created during run time if they do not already exist. For this I have to ascertain whether the database already has the table. If the table is not there I have to create it. I can write the code for creating the table. But how do I find out whether the table is already present in the database? What code I should include to do this?

Thanks in advance

- Anant

Reply With Quote
  #2  
Old September 30th, 2003, 02:49 AM
Silian's Avatar
Silian Silian is offline
Gogga
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: A long, long time ago, in a galaxy, far, far away...
Posts: 34 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
If you are using ms sql, you can use the sysobjects table to check if the table existes
Code:
sqlstr = "select name from sysobjects where name = 'tableName'"
rs.open sqlstr, conn
if rs.eof then
  'code to create table
end if


or (for any database) you can just route the error to a table create area, while selecting stuff from the table (I don't know if this is cheating)
Code:
on error goto createTable
sqlstr = "select top 1 * from tableName"
rs.open sqlstr, conn
  'the rest of the code
exit sub
createTable:
  'code to create table
  resume next


I know that there is a better way to do this, but I can't remember how, so I thought that I should post this until I (or someone else) finds it.

Reply With Quote
  #3  
Old October 6th, 2003, 10:27 AM
asnavale asnavale is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: India
Posts: 5 asnavale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
VB programming for database application

Thanks Silian.

But I am not using MS SQL. I am writing only in VB5 code. I tried the following code and it worked. Give your valuable comments.

...
...

Dim dbs As Database
Dim dbFile As String, Tbl As String
Dim FoundTbl As Boolean
Dim X

dbFile = "MyVBProject.mdb"
Tbl = "SampleTable"

Set dbs = OpenDatabase(dbFile)
FoundTbl = False

With dbs
For Each X In .TableDefs
If X.Name = Tbl Then
FoundTbl=True
End If
Next
End With

dbs.close

If FoundTbl = False Then
Call CreateTable
End If
...
...

- Anant Navale

Reply With Quote
  #4  
Old October 15th, 2003, 07:49 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Well, in Access it is MSysObjects that contains the table names

sqlstr = "select * from MSysObjects where name = 'tableName'"
rs.open sqlstr, conn
if rs.eof then
'code to create table
end if

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VB programming for database application


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway