Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6 Compare Databases, Add missing fields from one database to the other

Posted on 2010-08-17
4
Medium Priority
?
269 Views
Last Modified: 2012-06-27
Hey,

So im making an application that is run during my programs installation. The purpose of this is to compare the database that is in the installation, with the existing database found on the computer.

If the old database is missing coumns/ tables etc which are found in the new database, they are added in.

How do I do this?

Thanks,
Jessee
0
Comment
Question by:Letsgetcoding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33462118
What database are we talking ? Is it a sql-server or access database ?

Examples below were found at http://techrepublic.com.com/5208-6230-0.html?forumID=87&threadID=160570&messageID=1662730&tag=content;leftCol
There are many answers to this question - here's 3 
1st: (Most likely the fastest)

Run a query of the SysObjects Table

SELECT MSysObjects.Name, MSysObjects.Type
FROM MSysObjects
WHERE (MSysObjects.Name="Your Table Name") AND (MSysObjects.Type=1)

2nd: (sneaky but works)

On error resume next
err.number = 0
'Asssume your ADO data connection is cnn...
cnn.execute("DROP TABLE [YOUR TABLE NAME]")
'Discard error...
err.number = 0
'Create your table...

3rd: (Snaziest)
'Walk the Jet table collection...


Reference: (Use Late Binding if you do not want to reference)
Microsoft ActiveX Data Objects 2.x Library (This is ADODB)
Microsoft ADO Ext. 2.8 for DDL and Security (This is ADOX)


Call the fuction: msgbox TableExists("ABC")

Past the following code:

Option Explicit
'----------------------------------------------------------------
Public Function TableExists(TableName As String) As Boolean
On Error GoTo ErrorHandle:
Dim cnn As ADODB.Connection
'Dim cnn
Dim cat As ADOX.Catalog
'Dim cat
Dim tbl As ADOX.Table
'Dim tbl
'--------------------------------------------------------------
'Connect to the Database...
'--------------------------------------------------------------
Set cnn = CreateObject("ADODB.Connection")
'cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\YourDB.mdb;Persist Security Info=False"
cnn.Open
'--------------------------------------------------------------
'Set cat = New ADOX.Catalog
Set cat = CreateObject("ADOX.Catalog")
cat.ActiveConnection = cnn
'--------------------------------------------------------------
For Each tbl In cat.Tables
If tbl.Type = "TABLE" And tbl.Name = TableName Then
TableExists = True
End If
Next
'--------------------------------------------------------------
ExitProc:
On Error Resume Next
Set tbl = Nothing
Set cat = Nothing
cnn.Close
Set cnn = Nothing
Exit Function
ErrorHandle:
TableExists = False
GoTo ExitProc:
End Function

Open in new window

0
 
LVL 53

Accepted Solution

by:
Dhaest earned 1000 total points
ID: 33462124
Find Out Whether a Specific Column Exists in a Database Table
http://imar.spaanjaars.com/262/find-out-whether-a-specific-column-exists-in-a-database-table
0
 

Author Comment

by:Letsgetcoding
ID: 33462215
Hey,

Access database. A having a look at these links now.
0
 
LVL 5

Assisted Solution

by:BrianVSoft
BrianVSoft earned 1000 total points
ID: 33462567
My guess is that you (like the rest of us)  have a long standing database app that you regularly improve by adding new fields to the tables. And, when you offer a version upgrade, you need to add any new fields to the old previous version database..
We have an upgrade app that uses a 'hard programed' list of "new fields" to check if all of them are present - if any are missing, they are created..
This App also unpacks all the new exe's (from a winzip self extractor) to the resource folder of the main app.
Whenever we add a new field to our standard database, we also add a 'hard programed' item to the above list.
It uses VB6 DAO on an Access database.. If this model suits your situation, I could post extracts from the source code.
It uses statements like..
    Set NewField = xTaDef.CreateField(FieldNam$, FType, FSize)
    NewField.AllowZeroLength = True: NewField.Required = False
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 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