When data is returned from ado, It Is A recordset. In this case, the recordset cannot be directly bound to the grid, because
Is grid, and recordsource does not receive this type of data structure, it will produce an error
The correct method is to add a cursor and bind it to the grid.
Note that it is best not to bind the cursor returned from procedure directly to the grid.
Otherwise, the data will flash, and the computer is running fast and cannot be seen. The test method is to add a MessageBox after binding.
A simple method is to use a global variable to store the cursor.
Content written in clickprocedure of the button
Set procedure to "E: \ foxproproject \ sqlconnection. PRG"
Mycon = sqlconnection ("provider = sqloledb.1; Password = cxy; persist Security info = true; user id = sa; initial catalog = bussetup; Data Source = .")
& Create database commands
Comstring = "select top 10000 * from tables"
Public mytable as cursoradapter
Mytable = executenonquery (mycon, comstring)
& MessageBox (mytable)
& MessageBox (mytable. Fields (0). value)
Thisform. grid1.recordsourcetype = 1
Thisform. grid1.recordsource = "MERs"
Thisform. grid1.refresh ()
Thisform. Refresh ()
MessageBox ("done ")
In sqlconnection. PRGCode
& Use ADO to connect to SQL Server
Procedure sqlconnection
Parameters cstring
Local oconn as ADODB. Connection, ORS as ADODB. recordset
Oconn = Createobject ("ADODB. Connection ")
Oconn. Open (cstring)
Return oconn
End proc
Procedure executenonquery
Parameters oconn, comstr
Local ORS as ADODB. recordset ,;
Locursor as cursoradapter
ORS = oconn. Execute (comstr)
Locursor = Createobject ('cursoradapter ')
With locursor
. Alias = 'customer'
. Datasourcetype = 'ado'
Llreturn =. cursorfill (. F.,. F., 0, ORS)
Endwith
Return locursor
& Return ors
& Return ors. Fields (0). Value
End proc
How to bind a table to a grid
Set path to "E: \ foxproproject \ data \"
Close Databases
Open Database gsdata
Use gsdata! XL shared
Browse
Thisform. grid1.recordsourcetype = 0
Thisform. grid1.recordsource = "XL"
Thisform. grid1.refresh ()
Thisform. Refresh ()
MessageBox ("done ")