In VF, we can use ADO to obtain data and bind it to a form.
However, the use of ADO is not so convenient, for example, it is not convenient to insert and update data. In the local environment of VF, if the data environment is loaded
So it's easy,
Here we can use ADO in the data environment provided by VF to automatically generate cursoradapter
To generate the relevantCodeAnd then transform it.
The generated SCX file can be opened with editplus or utlraedit. You can see the code clearly from the inside.
Below is a code rebuild
Define class data1 as dataenvironment & Data Environment
Name = "dataenvironment"
Maximum = 220
Left = 1
Width = 520
Height = 200
Datasource =. null.
Datasourcetype = "Ado"
Procedure beforeopentables
* ** Select connection code: Do not remove
Local loconndatasource
Loconndatasource = Createobject ('ADODB. connection ')
* ** <Datasource>
& Loconndatasource. connectionstring = [provider = sqloledb.1; Password = cxy; persist Security info = true; user id = sa; INI] +;
& [TiAl catalog = bussetup; Data Source =.;]
Loconndatasource. connectionstring = constring
* ** </Datasource>
Loconndatasource. open ()
This. datasource = Createobject ('ADODB. recordset ')
This. datasource. cursorlocation = 3 & aduseclient
This. datasource. locktype = 3 & adlockoptimistic
This. datasource. activeconnection = loconndatasource
* ** End of select connection code: Do not remove
Endproc
Enddefine & add a cursor Class Object
Define class demo as cursoradapter
Usededatasource =. T.
Selectcmd = "select * from ........."
Cursorschema = "id I, date t"
Alias = "demotable"
Flags = 0
Keyfieldlist = "ID"
Tables = "... d"
Updatablefieldlist = "................"
Updatenamelist = "......................."
Usecursorschema =. T.
Name = "Demo"
Procedure init
* ** Setup code: Do not remove
Local llreturn
Do case
Case not pemstatus (this, '_ vfpsetup', 5)
This. addproperty ('_ vfpsetup', 0)
Case this. _ vfpsetup = 1
This. _ vfpsetup = 2
Case this. _ vfpsetup = 2
This. _ vfpsetup = 0
Return
Endcase
Set multilocks on
Llreturn = dodefault ()
* ** End of setup code: Do not remove
* ** Setup code: Do not remove
If this. _ vfpsetup = 1
This. _ vfpsetup = 2
Endif
Return llreturn
* ** End of setup code: Do not remove
Endproc
Procedure autoopen
* ** Setup code: Do not remove
If not pemstatus (this, '_ vfpsetup', 5)
This. addproperty ('_ vfpsetup', 1)
This. INIT ()
Endif
* ** End of setup code: Do not remove
Endproc
Enddefine
& Here are some tables
Define class grddemotable as grid
Columncount = 29
Left = 48
Recordsource = "demotable"
Recordsourcetype = 1
Top = 24
Name = "grddemotable"
Column1.controlsource = "demotable. ID"
Column1.name = "column1"
................
...............
Enddefine
Define class cxyform as form
Top = 0
Left = 0
Height = 386
Width = 587
Docreate =. T.
Caption = "cxyform"
Name = "form1"
Dataenvironment = "" & dataenvironment is an attribute of a form.
Procedure destroy
try
thisform. dataenvironment. closetables & close the table at the end of the destroy Process
catch to mexception
return. f.
endtry
thisform. hide
clear events
endproc
procedure unload
clear events
endproc
procedure load
* dataenvironment is instantiated, and the form attribute
* dataenvironment references this object. dataenvironment
* is not actually added to the form. thisform. dataenvironment
* is just a pointer to the dataenvironment object.
myde = Createobject ("data1")
thisform. dataenvironment = myde
myde. addobject ("demoname", "Demo")
& myde. demoname. selectcmd = "select top 10 * from ................ "
myde. demoname. selectcmd = comsql
* Open the table at the start of load.
thisform. dataenvironment. opentables
thisform. addobject ("BB", "grddemotable")
thisform. bb. visible =. t.
thisform. bb. width = thisform. width
thisform. bb. height = thisform. height
thisform. bb. top = 0
thisform. bb. left = 0
thisform. bb. column1.visible =. f.
thisform. bb. column2.visible =. f.
thisform. bb. column3.visible =. f.
thisform. bb. column4.visible =. f.
thisform. bb. column5.visible =. f.
thisform. bb. column6.visible =. f.
thisform. bb. column7.visible =. f.
thisform. bb. column8.header1. caption = "site name"
thisform. bb. column9.header1. caption = "full pass"
thisform. bb. column12.visible =. f.
thisform. bb. column13.header1. caption = "final amount"
Bindevent (this, "resize", this, "changesize ")
Endproc
Procedure changesize
Thisform. BB. width = thisform. Width
Thisform. BB. Height = thisform. Height
Endproc
Enddefine