Read and write to an access database using Javascript

前端 未结 2 405
无人及你
无人及你 2020-12-02 17:59

first I want to mention that I am aware that in web interaction with databases should
always be with server side languages due to security reasons and for the fact that

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 18:19

    First, make sure that '/\' and '\' (in connection string) is just a typo in SO.

    Second, here is a version of Delete command:

    function DeleteRecord() {
    var adoConn = new ActiveXObject("ADODB.Connection");
    var adoCmd = new ActiveXObject("ADODB.Command");
    
    adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\dbName.mdb'");
    adoCmd.ActiveConnection = adoConn;
    adoCmd.CommandText = "Delete * From tblName Where FieldName = 'Quentin'";
    adoCmd.Execute();
    
    adoConn.Close();
    }
    

    And, Edit command (without looping -> updates all [matching] records):

    function EditRecord() {
    var adoConn = new ActiveXObject("ADODB.Connection");
    var adoCmd = new ActiveXObject("ADODB.Command");
    
    adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\dbName.mdb'");
    adoCmd.ActiveConnection = adoConn;
    adoCmd.CommandText = "Update tblName Set FieldName = 'New Value' Where FieldName = 'Quentin'";
    adoCmd.Execute();
    
    adoConn.Close();
    }  
    

    Please note, I have not tested this (do not have Access right now), so there might be some syntax bugs...

    Hope it works and helps.

提交回复
热议问题