How to retrieve information from SQL Server about affected rows in Visual FoxPro 7.0 and later versions

Article translations Article translations
Article ID: 156034 - View products that this article applies to.
This article was previously published under Q156034
Expand all | Collapse all


Microsoft SQL Server and other server data sources frequently have statistical information about how many rows were affected by a particular SQL statement when it was executed. Microsoft Visual FoxPro 7.0 and later versions do not retrieve this information from the server for you. This article describes how to integrate using stored procedures on the server to retrieve this information.


When you are working with data on a server, you must know how many rows in the table were affected by a certain SQL command. This information is similar to the information that is provided by the _TALLY variable in Visual FoxPro.

This information is not available to you directly in Visual FoxPro, but there are ways to obtain that information if you want.

Visual FoxPro 7.0 and later versions support output parameters from stored procedures. This means that you can call a procedure that is located on the SQL Server-based computer and then that procedure returns information to the client application.

The following code example uses an existing table in the SQL Server Pubs database and creates the stored procedure on the SQL Server-based server. Create a program in Visual FoxPro, copy the code into the program, and then run the program from the Visual FoxPro Command window:
lcServername = "(local)"  && change the SQL Server name if you have to.
lcDatabase = "pubs"

TEXT to lcText noshow textmerge
 CREATE PROCEDURE upd_pubsauthors @state char(2), @zip char(5), @retcount int
  UPDATE authors SET state = @state
          WHERE  zip = @zip
     SELECT @retcount = @@ROWCOUNT

Mvar = 0
nhandle=Sqlstringconnect("Driver=SQL Server;SERVER="+lcServername+";DATABASE="+lcDatabase)
=SQLExec(nhandle,'drop procedure upd_pubsauthors') = -1
If SQLExec(nhandle,lcText) = -1
 List Memory Like atest

If SQLExec(nhandle,"{CALL upd_pubsauthors ('CA', '94609', ?@mvar)}") = -1
 List Memory Like atest
 ? Mvar
After the code runs, view the value that is echoed to the Visual FoxPro desktop. This value indicates the number of rows in the SQL Server table that are affected.


For more information about SQL Server stored procedures, see Microsoft SQL Server manuals.


Article ID: 156034 - Last Review: February 12, 2007 - Revision: 3.4
  • Microsoft Visual FoxPro 7.0 Professional Edition
  • Microsoft Visual FoxPro 8.0 Professional Edition
  • Microsoft Visual FoxPro 9.0 Professional Edition
kbautomation kbhowto kbinterop KB156034

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from