extracting .mdb file using a C program ?

M

Michelle

I'm trying to write a C program to read a Microsoft Access .mdb file
and convert the whole database
into a text file. If anyone has experience or knows what's involved
in doing this, please advise. Thanks.
 
A

Albert D. Kallal

Michelle said:
I'm trying to write a C program to read a Microsoft Access .mdb file
and convert the whole database
into a text file. If anyone has experience or knows what's involved
in doing this, please advise. Thanks.

You don't need ms-access installed ona windows box. Here is a windows
script that reads a table from a mdb file to a text file:

Set dbeng = CreateObject("DAO.DBEngine.36")
strMdbFile = "C:\Documents and Settings\Albert\My
Documents\Access\ScriptExample\MultiSelect.mdb"
Set db = dbeng.OpenDatabase(strMdbFile)
strQuery = "select * from contacts"
Set rs = db.OpenRecordset(strQuery)
rs.movefirst
If rs.EOF = true Then
quit
End If

strTextOut = "C:\t5.txt"
set fs = Wscript.CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(strTextOut, 2, True)
' 2 = write, 1 = read

do while rs.EOF = false
strOutText = rs("LastName")
ts.Writeline strOutText
rs.movenext
loop
ts.close
rs.close

the above text can be pasted into notepad. Then simply rename the extension
to .vbs. At that point you just built your first windows script.

the above will run on a windows xp, vista or win7 box without ms-access
having been installed....

You thus can use the com object DAO.DBEngine.36 to read data out of the
file. As mentioned, the above script should run on any recent windows box.
this includes a windows box that just had a fresh OS install and NO other
software installed.

You need nothing more then notepad and to copy your mdb file to the windows
box to get the data out...
 
N

Norman Yuan

If it is one-time conversion to get the data, writing a C program could be a
overkill. You can simply use MS Excel to connect to the *.mdb file (go to
Excel menu->Data->Import Exteranl Data->Import Data...), and import each
tables in the Db into a worksheet. Simple and fast.
 
T

Tom van Stiphout

On Fri, 17 Jul 2009 20:09:47 -0600, "Albert D. Kallal"

I would have used the GetString method of the ADO recordset object. No
looping required.

-Tom.
Microsoft Access MVP
 
D

David W. Fenton

If it is one-time conversion to get the data, writing a C program
could be a overkill. You can simply use MS Excel to connect to the
*.mdb file (go to Excel menu->Data->Import Exteranl Data->Import
Data...), and import each tables in the Db into a worksheet.
Simple and fast.

That assumes your data tables have few enough rows to not exceed
Excel's limits, or that your version of Excel is 2007.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top