Comparing Two Access Tables? 
Author Message
 Comparing Two Access Tables?

Im converting an older AS/400 RPG program to
Visual Basic.  Right now, both rely on the same
database (but each has its own copy).  My job
is to rewrite the old RPG program using VB. The
VB programs output must match the RPG programs
output exactly.

I would love to develop a tool that can automate
this comparison process on a table by table basis.  
Each file is its own table. Ideally, I should
simply be able to input the location of each file
and my utility would compare the two tables, looking
for differences in the values stored in the tables.

I think I know how to write most of this code, but
there is one problem I dont know how to solve. I
would rather not have to hard code each tables
column names.  Is there a way to extract at run-time
the names of every column in a table?

I would prefer to write this program using ADO, but
DAO is fine.

Im using VB6SP3 and ADO 2.1.  The database engine
is Jet.

Jim

-----------------** -- Posted from CodeGuru -- **-----------------
http://www.*-*-*.com/ ;       The website for VB programmers.



Mon, 11 Feb 2002 03:00:00 GMT  
 Comparing Two Access Tables?
Jim:

Use the recordset Fields collection.

In DAO, below is a direct extract from one of my applications that reads
the field names, types and sizes from the table.  I was using .DBF
files, but it would only require a slight change for Access tables.

' Open Database, using Datapath
        Set dbs =
DBEngine.Workspaces(0).OpenDatabase(frmSelect.cCL.DataPath, False,
False, "dBase IV")

        ' Open Recordset
        Set rst = dbs.OpenRecordset(m_DBF_File, dbOpenSnapshot)

        ' Determine number of fields in database
        m_NumFields = rst.Fields.Count

        ' Redim arrays for field names, types, sizes
        ReDim m_FieldNames(m_NumFields - 1)
        ReDim m_FieldTypes(m_NumFields - 1)
        ReDim m_FieldSizes(m_NumFields - 1)

        ' Get field names, types and sizes
        For i = 0 To m_NumFields - 1
            m_FieldNames(i) = rst.Fields(i).Name
            m_FieldTypes(i) = rst.Fields(i).Type
            m_FieldSizes(i) = rst.Fields(i).Size
        Next i

        ' Close database
        dbs.Close

In ADO, if your table is attached to an ADO data control, you can
similarly access the field names, types and sizes using (for the first
field):

FieldNames(0) = Adodc1.Recordset.Fields(0).Name
FieldTypes(0) = Adodc1.Recordset.Fields(0).Type
FieldSizes(0) = Adodc1.Recordset.Fields(0).DefinedSize

I trust this helps.

John....

Quote:

> Im converting an older AS/400 RPG program to
> Visual Basic.  Right now, both rely on the same
> database (but each has its own copy).  My job
> is to rewrite the old RPG program using VB. The
> VB programs output must match the RPG programs
> output exactly.

> I would love to develop a tool that can automate
> this comparison process on a table by table basis.
> Each file is its own table. Ideally, I should
> simply be able to input the location of each file
> and my utility would compare the two tables, looking
> for differences in the values stored in the tables.

> I think I know how to write most of this code, but
> there is one problem I dont know how to solve. I
> would rather not have to hard code each tables
> column names.  Is there a way to extract at run-time
> the names of every column in a table?

> I would prefer to write this program using ADO, but
> DAO is fine.

> Im using VB6SP3 and ADO 2.1.  The database engine
> is Jet.

> Jim

> -----------------** -- Posted from CodeGuru -- **-----------------
> http://www.codeguru.com/vb         The website for VB programmers.



Mon, 11 Feb 2002 03:00:00 GMT  
 Comparing Two Access Tables?
Jim,
Most databases such as SQL Server, DB2 and I suspect others have
"sysobject" and "syscolumns" tables. (The names would depend on the
database.) I typically query these tables to get a recordset with table and
columns names. Access unfortunately does allow direct queries to these "sys"
tables as far as I know.

Your only choice is to open the db and loop through the table and field
collections. There's info in the docs about how to do this. Hope this helps.

Oscar Bowyer

Quote:

>Im converting an older AS/400 RPG program to
>Visual Basic.  Right now, both rely on the same
>database (but each has its own copy).  My job
>is to rewrite the old RPG program using VB. The
>VB programs output must match the RPG programs
>output exactly.

>I would love to develop a tool that can automate
>this comparison process on a table by table basis.
>Each file is its own table. Ideally, I should
>simply be able to input the location of each file
>and my utility would compare the two tables, looking
>for differences in the values stored in the tables.

>I think I know how to write most of this code, but
>there is one problem I dont know how to solve. I
>would rather not have to hard code each tables
>column names.  Is there a way to extract at run-time
>the names of every column in a table?

>I would prefer to write this program using ADO, but
>DAO is fine.

>Im using VB6SP3 and ADO 2.1.  The database engine
>is Jet.

>Jim

>-----------------** -- Posted from CodeGuru -- **-----------------
>http://www.codeguru.com/vb         The website for VB programmers.



Mon, 11 Feb 2002 03:00:00 GMT  
 Comparing Two Access Tables?

Thanks!  - Jim

Quote:

>Im converting an older AS/400 RPG program to
>Visual Basic.  Right now, both rely on the same
>database (but each has its own copy).  My job
>is to rewrite the old RPG program using VB. The
>VB programs output must match the RPG programs
>output exactly.

>I would love to develop a tool that can automate
>this comparison process on a table by table basis.  
>Each file is its own table. Ideally, I should
>simply be able to input the location of each file
>and my utility would compare the two tables, looking
>for differences in the values stored in the tables.

>I think I know how to write most of this code, but
>there is one problem I dont know how to solve. I
>would rather not have to hard code each tables
>column names.  Is there a way to extract at run-time
>the names of every column in a table?

>I would prefer to write this program using ADO, but
>DAO is fine.

>Im using VB6SP3 and ADO 2.1.  The database engine
>is Jet.

>Jim

>-----------------** -- Posted from CodeGuru -- **-----------------
>http://www.codeguru.com/vb         The website for VB programmers.

-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/vb         The website for VB programmers.


Fri, 15 Feb 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Compare two access databases, size of tables

2. Comparing two tables and then updating one table.

3. comparing data in specific fields from two tables ???

4. Key field violation when comparing two tables

5. comparing two tables

6. Comparing Two Tables

7. Linking two Access tables in two databases

8. access-vba-code for comparing two strings?

9. Comparing two data fields in Access through Visual Basic

10. Compare structures of two Access databases

11. comparing field values from two different access databases

12. comparing tables within an access 2 db

 

 
Powered by phpBB® Forum Software