clientside access database with javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shuttered
    New Member
    • Oct 2007
    • 2

    clientside access database with javascript

    Can anyone help me on this? I just need more information on all aspects of it. For example : how to add, delete, edit fields. Can i add new tables etc..

    i know it is MS version of javascript so it only works in IE but thats perfect for my project and so is the clientside aspect of it as well, i know is easily hacked but I'm not worried about that since it is going to be used in an intranet setting.

    here is a sample of what i am talking about everything works except the edit and i know its bulky but its just so i can see how its going to work then i will really get started on it, PLEASE help

    [HTML]<html>
    <head>

    <script type="text/javascript">
    <!--
    var adOpenDynamic = 2;
    var adLockOptimisti c = 3;

    /* Path of database.
    */
    var strDbPath = "C:\\Sample.mdb ";

    /*
    Here is the ConnectionStrin g for Microsoft Access.
    If you want to use SQL or other databases, you hav to change the connection string..
    eg: SQL => var conn_str = "Provider=sqlol edb; Data Source=itdev; Initial Catalog=pubs; User ID=sa;Password= yourpassword";
    */
    var conn_str = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + strDbPath;

    function EditRecord() {
    var adoConn = new ActiveXObject(" ADODB.Connectio n");
    var adoRS = new ActiveXObject(" ADODB.Recordset ");

    adoConn.Open("P rovider=Microso ft.Jet.OLEDB.4. 0;Data Source='\\Sampl e.mdb'");
    adoRS.Open("Sel ect * From SampleTable Where Group = 'Quentin'", adoConn, 1, 3);

    adoRS.Edit;
    adoRS.Fields("G roup").value = "New Name";
    adoRS.Update;

    adoRS.Close();
    adoConn.Close() ;
    }


    function AddRecord() {
    var adoConn = new ActiveXObject(" ADODB.Connectio n");
    var adoRS = new ActiveXObject(" ADODB.Recordset ");

    adoConn.Open("P rovider=Microso ft.Jet.OLEDB.4. 0;Data Source='/\Sample.mdb'");
    adoRS.Open("Sel ect * From SampleTable", adoConn, 1, 3);

    adoRS.AddNew;
    adoRS.Fields("G roup").value = "Quentin";
    adoRS.Update;

    adoRS.Close();
    adoConn.Close() ;
    }

    function getAdoDb(strAdo Type){
    if (window.ActiveX Object){
    return new ActiveXObject(s trAdoType);
    }
    else{
    return ActiveXObject(s trAdoType);
    }
    }

    function showReports(){
    try{
    var strHtml ="";
    strHtml += "<table cellpadding=0 cellspacing=0 border=1 width= '100%' align=center>";
    strHtml += "<tr ><td align=center colspan=4><b>Sa mple Database Records</b></td></tr>";

    //Database Connection
    var conn = getAdoDb("ADODB .Connection");
    conn.open(conn_ str, "", "");

    //Recordset
    var rs = new ActiveXObject(" ADODB.Recordset ");
    //strQuery = "SELECT * FROM SampleTable";
    strQuery = "SELECT SampleTable.Dat e, SampleTable.Nam e, SampleTable.Gro up, SampleTable.Det ails FROM SampleTable";
    rs.open(strQuer y, conn, adOpenDynamic, adLockOptimisti c);

    if(!rs.bof){
    rs.MoveFirst();
    while(!rs.eof) {
    strHtml += "<tr>";
    strHtml += " <td><Font face ='tahoma'>" + rs.fields(0).va lue + "</font></td>";
    strHtml += " <td><Font face ='tahoma'>" + rs.fields(1).va lue + "</font></td>";
    strHtml += " <td><Font face ='tahoma'>" + rs.fields(2).va lue + "</font></td>";
    strHtml += " <td><Font face ='tahoma'>" + rs.fields(3).va lue + "</font></td>";
    strHtml += "</tr>";

    rs.MoveNext();
    }
    }
    else{
    //No Records.
    strHtml += "<tr colspan=4><td align=center><f ont color=red>No Records.</font></td></tr>";
    }
    conn.close();
    strHtml += "</table>";
    document.write( strHtml);
    }catch(ex){
    alert(ex.messag e);
    }
    }

    //-->
    </script>
    <title>Call Log Details</title>
    </head>

    <!--<body onload="show_me nu()">
    <div id="main" />-->
    <body>
    <script language="JavaS cript">
    showReports();
    </script>
    <input name="Button" type="button" value="add" onClick="AddRec ord()";><br>
    <input name="Button" type="button" value="delete" onClick="EditRe cord()";>
    </body>
    </html>
    [/HTML]

    thanks

    chad
    Last edited by gits; Oct 21 '07, 09:47 AM. Reason: added code tags
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Since this is a javascripts issue, I'm going to move it to the javascript/ajax forum!

    Welcome to TheScripts!

    Linq ;0)>

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Why not use an UPDATE query and make the edit via SQL?

      Comment

      • shuttered
        New Member
        • Oct 2007
        • 2

        #4
        Originally posted by acoder
        Why not use an UPDATE query and make the edit via SQL?



        My only resources are javascript and ms access all clientside.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by shuttered
          My only resources are javascript and ms access all clientside.
          I meant instead of a SELECT query, use an UPDATE query, e.g.[CODE=sql]UPDATE SampleTable set Group = "New Name" where Group = "Quentin"[/CODE]

          Comment

          • cygnusx197
            New Member
            • Dec 2007
            • 1

            #6
            Hi. I'm interested in learning more about this technique but I don't know where to start.

            I'm trying to prototype something like an asp.net gridview/details view kind of thing that has to use client side code and an access mdb (because it's completely offline - no IIS, .net etc).

            Does anyone have any urls? I'm lost in google land..... Thanks

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Welcome to TSDN!
              Originally posted by cygnusx197
              Hi. I'm interested in learning more about this technique but I don't know where to start.

              I'm trying to prototype something like an asp.net gridview/details view kind of thing that has to use client side code and an access mdb (because it's completely offline - no IIS, .net etc).

              Does anyone have any urls? I'm lost in google land..... Thanks
              What code do you have so far?

              Comment

              Working...