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_Co nn'}) {
$Conn = $Server->CreateObject("ADO DB.Connect ion");
$Conn->Open( "MyDSN","","");
$Session->{'Session_Conn'} =$Conn;
}
$rst = $Server->CreateObject("ADO DB.Records et");
$Sqlstat = "SELECT * FROM Mytable where UserID = \'$userid\'";
$rst->Open($Sqlstat,$Sessi on->{'Sess ion_Conn'} ,$adopenke yset);
$rst->Fields("City")->{Val ue}="city 1";
$rst->Update;
$rst->Close;
========================== ========== ========== ========== =
I'm working on Win95,PWS,MS Access97,ActivePerl Build502
Any advice is highly appreciated!
Thanks
Leon
==========================
$adopenkeyset=1;
my $Conn;
if(!$Session->{'Session_Co
$Conn = $Server->CreateObject("ADO
$Conn->Open( "MyDSN","","");
$Session->{'Session_Conn'}
}
$rst = $Server->CreateObject("ADO
$Sqlstat = "SELECT * FROM Mytable where UserID = \'$userid\'";
$rst->Open($Sqlstat,$Sessi
$rst->Fields("City")->{Val
$rst->Update;
$rst->Close;
==========================
I'm working on Win95,PWS,MS Access97,ActivePerl Build502
Any advice is highly appreciated!
Thanks
Leon
What is the error you're getting?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
$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.
$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.
ASKER
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")->{Val ue}=$Reque st->Form(' year')->It em;
But it did wrongly. I would like to know how to update a field date type is number or date/time.
I use following statement to update a number field:
$rst->Fields("year")->{Val
But it did wrongly. I would like to know how to update a field date type is number or date/time.
ASKER
I got the answer by myself. It's actually very simple, I made a mistake. Anyway, I give you 200 points.