S
suntisuka
First of all, I'm sorry to repost this question again. First one is posted in wrong group.
I write this code to test Mode property. I use adModeRead and expect program to generate an error like "Can not update record". But it does not, It still able update records. Could you please tell me what is wrong in my code ?
I write code in AccessXP with ADO 2.7 Library to access data in Pubs sample database from SQL Server 2000.
Here is my code :
Dim cnn1 As ADODB.Connection
Dim rst1 As ADODB.Recordset
Dim strCnn As String
strCnn = "Provider=sqloledb;Data Source=COMPAQ;Initial Catalog=Pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Mode = adModeRead
cnn1.Open strCnn
Set rst1 = New ADODB.Recordset
rst1.Open "Titles", cnn1, adOpenDynamic, adLockOptimistic
Do Until rst1.EOF
If Trim(rst1!Type) = "psychology" Then
rst1!Type = "self_help"
rst1.Update
End If
rst1.MoveNext
Loop
rst1.Close: Set rst1 = Nothing
cnn1.Close: Set cnn1 = Nothing
MsgBox "Finish"
TIA,
Suntisuk
I write this code to test Mode property. I use adModeRead and expect program to generate an error like "Can not update record". But it does not, It still able update records. Could you please tell me what is wrong in my code ?
I write code in AccessXP with ADO 2.7 Library to access data in Pubs sample database from SQL Server 2000.
Here is my code :
Dim cnn1 As ADODB.Connection
Dim rst1 As ADODB.Recordset
Dim strCnn As String
strCnn = "Provider=sqloledb;Data Source=COMPAQ;Initial Catalog=Pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Mode = adModeRead
cnn1.Open strCnn
Set rst1 = New ADODB.Recordset
rst1.Open "Titles", cnn1, adOpenDynamic, adLockOptimistic
Do Until rst1.EOF
If Trim(rst1!Type) = "psychology" Then
rst1!Type = "self_help"
rst1.Update
End If
rst1.MoveNext
Loop
rst1.Close: Set rst1 = Nothing
cnn1.Close: Set cnn1 = Nothing
MsgBox "Finish"
TIA,
Suntisuk