Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server Query in FoxPro

Status
Not open for further replies.

57chevy

Programmer
Jan 4, 2000
29
US
I'm coding a program in VFP6 which connects to a SQLServer Database in order to extract certain records from one of the tables in the database. Can anyone tell me how to code the program so that the end user of the program will get a "messagebox" or some other
user interface where he can type in a SQL
statement determining which records will be extracted? Thanks in advance for help.
 
Create a VFP form with a textbox (let's call it txtSQLCommand). Add a command button called cmdGo labelled "Go".

In the cmdGo.Click method add code similar to the following:

[tt]if empty(ThisForm.txtSQLCommand.Value)
return
endif
* establish connection
nHandle = SQLSTRINGCONNECT("driver={SQL Server};SERVER=\\MyServer;UID=MyUser;PWD=MyPwd;DATABASE=MyDb")
assert nHandle > 0
nResult = sqlexec(nHandle, trim(ThisForm.txtSQLCommand.Value), "curResult")
if nResult > 0 and reccount("curResult") > 0
browse
endif[/tt]

Obviously, this is pretty bare-bones, and lacking error checking and other niceties.
 
Duh, Why didn't I think of that. Thanks a lot for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top