/    Sign up×
Community /Pin to ProfileBookmark

Writing to an access database table

I am trying to over write an existing index in a mdb table. I don’t quite have the syntax down. I see the table as a 2X2 array, so I tried to treat it as such. But I am not sure I am parsing the table correctly. Here is the code. Is there an easier way? I tried the RS.Find() but that did not return anything. Any help would be much appreciated.

function onSubmit()
{
var AOI = document.getElementsByName(“AOI”);
var Layer = document.getElementsByName(“Layer”);
var AIOholder = AOI[0];
var Layerholder = Layer[0];

//Path is correct

var myConnect = “Provider=Microsoft.Jet.OLEDB.4.0; Data Source=”+DBPath;

var ConnectObject = new ActiveXObject(“ADODB.Connection”);
var sql=”SELECT * FROM 1_OverView_Board_For_Status;”;
ConnectObject.Open(myConnect);

var RS = ConnectObject.Execute(sql);

var fieldCount = RS.Fields.Count;

alert(“AOI ” + AIOholder.value);
alert(“Layer ” + Layerholder.value);
alert(“Field Count ” + fieldCount);

var recordCount = RS.Fields.Count;
var x = 0;
var header;
var getFieldNames = false;

//RS.Find(“Layer=street”)

while (!RS.EOF)
{
if (x >= recordCount)
{
x = 0
}
if (!getFieldNames)
{
while (x <= recordCount-1)
{
if( RS.Fields(x).Name == Layerholder.value)
{
alert(“Here” + RS.Fields(x).Name);
x=0;
while (x <= recordCount-1)
{
alert(“Looking for ” + RS.Fields(x).Value + ” AOI: ” + AIOholder.value);
if( RS.Fields(x).Value == AIOholder.value)
{
[B]RS.Fields(x).Value= ‘QC’;[/B]
[B]Here is where I want to alter the value[/B]

return;
}
x++
}
}
x++;
}
}

RS.MoveNext();
}

alert(“Exiting”);

RS.Close();
ConnectObject.Close();
return;

}

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@Banana_AnandaJun 28.2007 — I'm lost here. May well be my fault. Im still not 100% certain what you want done.

Confused by this:

[code=php]var fieldCount = RS.Fields.Count;
// fair enough
...
var recordCount = RS.Fields.Count;
// Not strictly speaking. Is this what you want ?
// (We can't get the record count directly with a forward only cursor)[/code]


A couple of tidbits:


[code=php]if (x >= recordCount) { x = 0 } // if(x = x % recordCount)

while (x <= recordCount-1) // while (x < recordCount)[/code]


Could you post the code with the "unknown to us" values filled in

eg

[FONT="Courier New"]AIOholder.value = ???[/FONT]

Any chance of attaching a sample of the relevant DB table ?


-------------

Couldn't this be done purely with SQL ?
Copy linkTweet thisAlerts:
@fuknlightnauthorJun 28.2007 — Sorry about the vagueness of the code here is a better version. I tried to accomplish it with sql. Still having problems.


function onSubmit()

{

var AOI = document.getElementsByName("AOI"); // "1"

var Layer = document.getElementsByName("Layer");"PopP"

var AIOholder = AOI[0];

var Layerholder = Layer[0];


var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+DBPath;

var ConnectObject = new ActiveXObject("ADODB.Connection");

var sql="SELECT * FROM 1_OverView_Board_For_Status WHERE AOI = '" + AIOholder.value + "' ;";

ConnectObject.Open(myConnect);

var RS = ConnectObject.Execute(sql);

var fieldCount = RS.Fields.Count;


alert("Layer " + Layerholder.value);


var recordCount = RS.Fields.Count;

var x = 0;

var header;

var getFieldNames = false;

while (x <= recordCount-1)

{ if( RS.Fields(x).Name == Layerholder.value)

{

[B]

var sql2="UPDATE 1_OverView_Board_For_Status WHERE AOI = '" + AIOholder.value +"'& " + RS.Fields(x).Name + " SET = 'QC' ;";[/B]


alert(sql2);

var RS = ConnectObject.Execute(sql2);

return;

}

x++

}



alert("Exiting");

RS.Close();
ConnectObject.Close();
return;

}

[upl-file uuid=e572b932-0117-453c-bae2-ef99d6b7f6de size=60kB]Test.zip[/upl-file]
Copy linkTweet thisAlerts:
@Banana_AnandaJun 28.2007 — I'm still poring over it, but here's a couple of starters (Trying to get it working over here).

[FONT="Courier New"]var AOI = document.getElementsByName("AOI"); [COLOR="Green"]// 1 [/COLOR][/FONT]

getElementById returns an element reference, but you say I should hard code this value as 1 (a number !).

[FONT="Courier New"]var AIOholder = AOI[0];[/FONT]

Then we want the first member of [FONT="Courier New"]AOI[/FONT]. What's going on ?

  • - Similarly with [FONT="Courier New"]Layer / LayerHolder[/FONT].
  • Copy linkTweet thisAlerts:
    @Banana_AnandaJun 28.2007 — Ahhh. [FONT="Fixedsys"]getElementsByName[/FONT]. Sorry.

    OK. I'm going with these sample values:

    [FONT="Courier New"]AIOholder.value = 1;

    Layerholder.value = "PopP";[/FONT]
    Copy linkTweet thisAlerts:
    @Banana_AnandaJun 28.2007 — Using those values, the resulting SQL2 string is:

    [FONT="Fixedsys"]UPDATE 1_OverView_Board_For_Status WHERE AOI = '1'& PopP SET = 'QC';[/FONT]

    That's a little garbled. What should it be ?
    Copy linkTweet thisAlerts:
    @fuknlightnauthorJul 02.2007 — You were right on with the SQL statement.

    It worked with:

    "SELECT * FROM 1_OverView_Board_For_Status WHERE AOI = '" + AIOholder.value + "' ;";

    Thanks so much for the help!
    ×

    Success!

    Help @fuknlightn spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...