FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ADO
Posts: 310
Joined: Mon Oct 10, 2005 05:10 AM
ADO
Posted: Tue Feb 09, 2010 09:15 AM

Hi All

I have the following code working - connecting to a MYOB ( accounting software)
but I would like to add a record to the table.

include "fivewin.ch"

function main()
local cStr,oCon,oRecSet,oRs,cn,nCnt := 0

cStr := "Driver={MYOAU0901}; TYPE=MYOB; UID=Administrator; PWD=;DATABASE=C:\Premier125\Clearwtr.myo; HOST_EXE_PATH=C:\Premier125\MYOBP.exe;NETWORK_PROTOCOL=NONET; DRIVER_COMPLETION=DRIVER_NOPROMPT"

if oCon == nil
oCon := TOleAuto():new("ADODB.Connection")
oCon:ConnectionString := cStr
TRY
oCon:Open()
lConnect := .t.
CATCH
oCon := nil
MsgInfo('Connect Fail')
return nil
END
else
lConnect := .t.
endif

if oCon != nil .and. oRs == nil
oRs := TOleAuto():new( "ADODB.RecordSet" )
oRs:ActiveConnection := oCon
oRs:Source := "select * from Cards"
oRs:LockType := 4 // adLockOptimistic
oRs:CursorLocation := 3 //adUseClient
oRs:CacheSize := 100
TRY
oRs:Open()
CATCH
MsgInfo('Table Open Failure')
return nil
END
endif

if oRs:RecordCount() > 0
do while ! oRs:eof()
MsgInfo(oRs:Fields( "LastName" ):Value )
oRs:MoveNext()
enddo
SysRefresh()
endif

return(nil)

Posts: 310
Joined: Mon Oct 10, 2005 05:10 AM
Re: ADO
Posted: Tue Feb 09, 2010 09:21 AM

Hi All

Would I be better to use the ADORDD if so where to I find it - I am
using xHarbour.

Cheers

Colin

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: ADO
Posted: Tue Feb 09, 2010 09:28 AM
Dear Mr.Colin,

Update an existing record

Code (fw): Select all Collapse
cSql:=""
cSql+="UPDATE Invoice SET Bill_Amount = 100 WHERE Invoice_No = 1021"
TRY
   oConnection:Execute(cSql)
CATCH oError
   MsgInfo("Could not update")
   ShowSqlError(oError)
   Return .F.
END


// Now Insert a record
Code (fw): Select all Collapse
cSql:=""
cSql+="INSERT INTO Invoice ([Bill_No], [Bill_Amount])  VALUES (1022,2000.00)"
TRY
   oConnection:Execute(cSql)
CATCH oError
   MsgInfo("Could not add")
   ShowSqlError(oError)
   Return .F.
END


There are other ways too.

Regards
Anser
Posts: 310
Joined: Mon Oct 10, 2005 05:10 AM
Re: ADO
Posted: Tue Feb 09, 2010 09:42 AM

Hi Anser

I tried this code but it failed

if MsgYesNo('add')
cSql:=""
cSql+="INSERT INTO Cards ([Lastname]) VALUES (Techdata Software)"
TRY
oRs:Execute(cSql)
CATCH oError
MsgInfo("Could not add")
//ShowSqlError(oError)
Return .F.
END
endif

Cheers
Colin

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: ADO
Posted: Tue Feb 09, 2010 09:58 AM
Hi Mr.Colin

Code (fw): Select all Collapse
cSql+="INSERT INTO Cards ([Lastname]) VALUES ('Techdata Software')"

I found that ' ' is missing. Please check the oError, to understand where the problem is. It could be a SQL syntax error. You column last name is supposed to store a character string (Char or VarChar)

Regards
Anser
Posts: 310
Joined: Mon Oct 10, 2005 05:10 AM
Re: ADO
Posted: Tue Feb 09, 2010 10:05 AM

Hi Anser

Still no luck - where do I find ShowSqlError

regards

Colin

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: ADO
Posted: Tue Feb 09, 2010 10:18 AM
Dear Mr.Colin
Code (fw): Select all Collapse
Local oError
TRY
   oCmd:Execute()
CATCH oError
     MsgInfo( " Error No:  "+AllTrim(STR(oError:NativeError))+CRLF+;
          " Description :  "+oError:Description)
END


Regards
Anser
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: ADO
Posted: Tue Feb 09, 2010 10:26 AM
Code (fw): Select all Collapse
*---------------------------------------------------*
Function ShowSqlError(oError)
*---------------------------------------------------*
FOR EACH oError IN oApp:oConnection:Errors
   MsgInfo( " Error No:  "+AllTrim(STR(oError:NativeError))+CRLF+;
          " Descripcion :  "+oError:Description, oApp:cAppName)
   oApp:nLastErrorNo:=oError:NativeError
NEXT
RETURN ( NIL )
Posts: 310
Joined: Mon Oct 10, 2005 05:10 AM
Re: ADO
Posted: Tue Feb 09, 2010 12:18 PM

Hi Anser

Still cant get oErrors to work - I have sent an email to the company that
provides the SDK to see if they can offer some help.

Appreciate you assistance.

Cheers

Colin

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: ADO
Posted: Wed Feb 10, 2010 07:05 AM

Its much happier to deal with ADO directly than to use ADORDD, because we have full control on the code we use.

ADORDD is good when there is not enough time to learn ADO or to quickly convert a legacy application in DBF syntax.

In this case it appears to be an ODBC driver but not a full OLEDB provider. All functionality of ADO may not be available and is restricted by the feautures of ODBC and what the provider chose to provide. We can use ADO with the limitations inherent with the Driver that is provided.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion