Link to home
Start Free TrialLog in
Avatar of leonzhou
leonzhou

asked on

ADO update problem

I encounted the problem when I use ADO to update table: I can retrieve value, but not update).Following is my code piece:
=========================================================
$adopenkeyset=1;
my $Conn;
if(!$Session->{'Session_Conn'}) {
$Conn = $Server->CreateObject("ADODB.Connection");
$Conn->Open( "MyDSN","","");
$Session->{'Session_Conn'}=$Conn;
}
$rst = $Server->CreateObject("ADODB.Recordset");
$Sqlstat = "SELECT * FROM Mytable where UserID = \'$userid\'";
$rst->Open($Sqlstat,$Session->{'Session_Conn'},$adopenkeyset);
$rst->Fields("City")->{Value}="city 1";
$rst->Update;
$rst->Close;
=========================================================
I'm working on Win95,PWS,MS Access97,ActivePerl Build502

Any advice is highly appreciated!
Thanks
Leon
Avatar of rajgn
rajgn

What is the error you're getting?
ASKER CERTIFIED SOLUTION
Avatar of sybe
sybe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leonzhou

ASKER

Sybe,
I didn't try :
===============================
$Sqlstat = "UPDATE Mytable SET city = 'city 1' where UserID = \'$userid\'";
$Conn->Execute($Sqlstat);
==============================
I will try it tonight, and let you know. But I also want to use UPDATE method of ADO recordset.




ragjn,

I didn't get any error message from Errors collection.
$Sqlstat = "UPDATE Mytable SET city = 'city 1' where UserID = \'$userid\'";
$Conn->Execute($Sqlstat);

This worked. But I couldn't give you 200 points. Because I want to use Recordset not Command. I didn't make it clear in my title, and your answer did solve "ADO Updade Problem", I decide to give you 100 points. But I don't know how to give it to you. Please let me know. And again, if you can help me to find out why Recordset couldn't update, or solve this use Recordset, I will give you another 200 points. That means total 300 points.

I found the problem in my code. So, I couldn't give you another 200 points. So far, I will get 100 points. But I have another question. If you can answer it, I give you total 200 points.
I use following statement to update a number field:
$rst->Fields("year")->{Value}=$Request->Form('year')->Item;
But it did wrongly. I would like to know how to update a field date type is number or date/time.
I got the answer by myself. It's actually very simple, I made a mistake. Anyway, I give you 200 points.