View Single Post
  #1 (permalink)  
Old 03-15-2009, 01:09 PM
meester meester is offline
Senior Member
 
Join Date: Feb 2003
Posts: 212
Default DBF-file drives me crazy

I've got a problem with my dbf connection through swfkit.
The dbf-file is created with an outdated dbf program,
therefore i must change the first bitvalue as pointed in this post:

Code:
function ChangeFile(){

    trace("Copy original file to app-dir and change it")

// Original file is in this folder
    path = "c:\\DOELFOLDER\\ordp.dbf";
    src = new File(path);
    trace(src.name)
    destPath = doelpuntmap
    
    b = getAppDir() + "dp.dbf"
    src.copy(b);
    
    var f = new FileStream(b, "r+");
    f.put(0x03);
    f.close();
    
}
This code is working.

Then I try to connect to the dp.dbf-file like this:
Code:
function getDBFRecords(){    
    conn2= new ActiveXObject("ADODB.Connection");
    conn2.connectOK = false;
    conn2.ConnectComplete = function (err, status, cnt){
        trace(err.Description+"   " + status.value)
        if (typeof err != "undefined"){
            trace(err.Description);
             return;
      
            
            
        }else{
            conn2.connectOK = true;
            trace("Connect complete!");
        }
    }
    conn2.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+getAppDir()+";Extended Properties='dBase IV';");
    
    if (!conn2.connectOK){
            trace("Failed to connect to the DB");
            return;
    }

    var ds = new ActiveXObject("ADODB.Recordset");
    ds.open("select * from dp.dbf", conn2, 1, 2);
    dpdoelen = []
    ds.moveFirst();
    for(var i=0;i<200;i++){
        if(ds.Fields["DOEL"].value){
            dpdoelen.push({naam:ds.Fields["ONDEEL"].value.toString()+"___"+ds.Fields["DOEL"].value.toString()+"|"+ds.Fields["NUMMER"].value})
            ds.moveNext()
            trace(ds.Fields["DOEL"].value.toString())
        }else{
            break;
        }
    }
    ds.close()
    return dpdoelen
}
When I run this code just after i changed the file, I can't connect to the database.
But when I try the code seperatly (without changing the file at the same time) with the changed file, it works.

Another issue is that I can only see the records in preview mode.
When i compile the program, it doesn't work anymore!

My sourcefile can be downloaded here

Any help is appreciated

Last edited by meester; 03-16-2009 at 06:09 PM.
Reply With Quote