How does FoxPro use ADO to extract data from SQL Server and put it in grid?

Source: Internet
Author: User

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 ")

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.