#115768 - 2004-03-09 07:31 PM
Help with updating Access DB!
|
emw1972
Fresh Scripter
Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
|
I'm attempting to update an access database with the below script. It doesn't work. I've been working on this thing all day! Can someone help? Below is the code.
I can insert the first record just fine, but my code for the update never gets touched.
On my Access database, the field MAC is a primary key.
Code:
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=\\ngne-j6-05\test\erictest.mdb') $recordset = DBGetRecordset($objConn,"SELECT MAC FROM Table1 WHERE MAC='$MACADDR'") If $recordset.recordcount <> 1 for each $record in $recordset $=Messagebox("Getting Here!","return code") $recordsetfields=split($record,chr(10)) for each $field in $recordsetfields $retcode = DBExecuteSQL($objConn,"UPDATE Table1(DateWritten,TimeWritten,Workstation,IP,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')") next next Else ; This means that there is no record in the table that contains this MAC. Insert record now.... $=Messagebox("You are here!!!!","return code") $retcode = DBExecuteSQL($objConn,"INSERT INTO Table1(DateWritten,TimeWritten,Workstation,IP,MAC,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$MACADDR','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')") EndIf
|
|
Top
|
|
|
|
#115770 - 2004-03-09 07:41 PM
Re: Help with updating Access DB!
|
emw1972
Fresh Scripter
Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
|
Ok, I see that I'm missing that. I'll fix that in a minute.
What's the best way to see if my SELECT statement returns anything from my table???
Thanks for the prompt reply!
Eric
|
|
Top
|
|
|
|
#115772 - 2004-03-09 09:17 PM
Re: Help with updating Access DB!
|
emw1972
Fresh Scripter
Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
|
You know of an example of checking the contents of a return variable?
I'm having issues with checking for an empty recordset...
Thanks!
|
|
Top
|
|
|
|
#115774 - 2004-03-10 01:05 PM
Re: Help with updating Access DB!
|
emw1972
Fresh Scripter
Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
|
Thanks for your post! I greatly appreciate your assistance.
I guess I'm used to VB and how it prompts you for available options, if any were available, after I would type in "recordset." Like recordset.count, recordset.eof, etc, etc.
I'm working with Kixtart in notepad. Is another tool available? As you can obviously tell, I'm new to this.
I do have a few more code questions though...
With the below code, if my Access DB is empty, it will insert a record.
On the next run of this code (when I logoff/logon) I get a Scriptlogic error message about the execution of this script.
I don't understand why it doesn't work. If the recordset is not empty, I would expect it to go to the ELSE statement and send me a messagebox. Do I need to do some sort of other check?
Code:
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=\\ngne-j6-05\test\erictest.mdb') $recordset = DBGetRecordset($objConn,"SELECT MAC FROM Table1 WHERE MAC='$MACADDR'") $=Messagebox("TEST 1"," ") If $recordset='' ; This means that there is no record in the table that contains this MAC. Insert record now.... $=Messagebox("TEST 2"," ") $retcode = DBExecuteSQL($objConn,"INSERT INTO Table1(DateWritten,TimeWritten,Workstation,IP,MAC,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$MACADDR','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')") Else $=Messagebox("TEST 3"," ") EndIf $retcode = DBConnClose($objConn)
|
|
Top
|
|
|
|
#115776 - 2004-03-13 02:30 PM
Re: Help with updating Access DB!
|
Chaguito
Getting the hang of it
Registered: 2002-05-17
Posts: 53
|
Quote:
I'm attempting to update an access database with the below script. It doesn't work. I've been working on this thing all day! Can someone help? Below is the code.
I can insert the first record just fine, but my code for the update never gets touched.
On my Access database, the field MAC is a primary key.
Code:
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=\\ngne-j6-05\test\erictest.mdb') $recordset = DBGetRecordset($objConn,"SELECT MAC FROM Table1 WHERE MAC='$MACADDR'") If $recordset.recordcount <> 1 for each $record in $recordset $=Messagebox("Getting Here!","return code") $recordsetfields=split($record,chr(10)) for each $field in $recordsetfields $retcode = DBExecuteSQL($objConn,"UPDATE Table1(DateWritten,TimeWritten,Workstation,IP,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')") next next Else ; This means that there is no record in the table that contains this MAC. Insert record now.... $=Messagebox("You are here!!!!","return code") $retcode = DBExecuteSQL($objConn,"INSERT INTO Table1(DateWritten,TimeWritten,Workstation,IP,MAC,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$MACADDR','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')") EndIf
Instead of using
If $recordset=''
use
IF UBOUND($recordset)=-1
This means that if recordset is empty. I tried it the same way you did and most of the times gave me errors.
_________________________
Chaguito, MCP
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 927 anonymous users online.
|
|
|