I am trying to add records to sqlserver using ado.
The connections opens correctly & so does the recordset. However addnew does not seem to work. I am also unable to trap the error. i AM USING vfp 7.0. Can anyone tell me what I am doing wrong.
TIA
Alhad
The code is something like this.
*********************
select * from photographers where into array laPhoto
Local Err,cOldErr
cOldErr = On("error")
Err = .F.
On Error Err = .T.
** CREATING CONNECTIONS **
oConnection = CreateObject("adodb.connection")
oNewphotoRS = CREATEOBJECT("ADODB.RECORDSET")
**
With oConnection
.ConnectionString ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=PhotoMi;Data Source=ASMHOME"
.Open
EndWith
** OPENING RECORDSET **
oNewphotoRs.open("Select * from photographers",oConnection)
IF ERR
WAIT WINDOW "Error opening recordset"
ENDIF
**
oNewphotoRs.ActiveConnection.BeginTrans
FOR i = 1 TO ALEN(laPhoto,1)
oNewphotoRs.Addnew
oNewphotoRs.Fields(0) = laPhoto(i,1)
oNewphotoRs.Fields(1) = laPhoto(i,2)
WAIT WINDOW oNewphotoRs.Fields("name").Value
IF Err
For Each oError In oNewphotoRs.oConnection.Errors
With oError
?.Number,.Description
EndWith
Next oError
EXIT
ENDIF
ENDFOR
IF ERR
WAIT WINDOW "ERROR ADDIING RECORDS" && This is because I am unable
to display the error description above
ENDIF
ONewphotoRs.UpdateBatch
If Err
ONewphotoRs.ActiveConnection.RollBackTrans
ONewphotoRs.CancelBatch
Else
ONewphotoRs.ActiveConnection.CommitTrans
Endif
On Error &cOldErr
oConnection.Close
RELEASE oConnection,oNewphotoRs
return
Only direct experience is Knowledge;
Everything else is just Information.