Page 1 of 1

ADO and MySql

Posted: Tue Jul 09, 2013 9:18 am
by Colin Haig
Hi All

I a trying to use MySQL and ADO - I have a connection to the database and can open a table
but not sure what code to use to add records - according to a wiki page I found called ado-related stuff I can do the following

oRs:AddNew()
oRs:Fields('code'):Value := 'Test')
oRs:Update()

That code does not produce any errors but the record is not added

the other way is to use a insert statement which I have got to work.

Is it worth using AdoRDD ( not sure if it works with xHarbour or where I get it from )

Cheers

Colin

Re: ADO and MySql

Posted: Tue Jul 09, 2013 10:01 am
by lucasdebeltran
Hello,

Please, see TDataRow class explained in whatsnew.txt.

Very good class.

Re: ADO and MySql

Posted: Tue Jul 09, 2013 12:56 pm
by Rick Lipkin
Colin

Nothing specifically wrong with your addnew() and Update() .. please check how you create your Recordset and I suggest using these parameters :

Code: Select all

oRs := TOleAuto():New( "ADODB.Recordset" )
oRs:CursorType     := 1        // opendkeyset
oRs:CursorLocation := 3        // local cache
oRs:LockType       := 3        // lockoportunistic

cSql := "Select * From [YourTable] "

TRY
   oRs:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening YOURTABLE table" )
   RETURN(.F.)
END TRY

oRs:AddNew()
oRs:Fields("YourField"):Value := "Test"
oRs:Update()

xBrowse( oRs )

oRs:CLose()
 
The above code assumes that you have a Primary key that is auto created... xConnect is your connection string to MySql.

Rick Lipkin

Re: ADO and MySql

Posted: Tue Jul 09, 2013 11:45 pm
by Colin Haig
Thanks Rick - much appreciated.

Colin