Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2010-08-17
4
Medium Priority
?
273 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
  • 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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

572 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