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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run .PRG 1

Status
Not open for further replies.

stathread

Programmer
Jan 17, 2006
38
US
Is there a way to open a dbf and run a fox pro .prg on the dbf?

for example.

string myExecuteQuery = "use "+filename;
string myExecuteQuery2 = "do c:\prog.prg";
 
I still have not got this to work?

string path = openFileDialog1.FileName;
OleDbConnection oConn = new OleDbConnection(@"Provider=VFPOLEDB.1;DataSource=@"+path+";Mode=ReadWrite;");
oConn.Open();
OleDbCommand oCom = new OleDbCommand("do c:\prog.prg");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
 
stathread,

I've never seen any documentation that says the DO command is supported within the VFP OLEDB provider. A quick test with a a single line of code in a PRG to create a table pretty much confirms that it doesn't work (even if compiled to an FXP) - errors with
error said:
Message="One or more errors occurred during processing of command."
Source="Microsoft OLE DB Provider for Visual FoxPro"
ErrorCode=-2147217900

While the following does create the table as expected...
Code:
OleDbConnection oConn = new OleDbConnection("provider=VFPOLEDB.1;data source='C:\\';password='';user id=''");
oConn.Open();
OleDbCommand oCom = new OleDbCommand("Create Table ('C:\\Testing.DBF') (Name C(30))", oConn);
oCom.ExecuteNonQuery();

There were some useful commands added and fixes in the last version of the VFP OLEDB provider, but none of them quite the magnitude of what you are looking for here I'm afraid.

boyd.gif

SweetPotato Software Website
My Blog
 
stathread,

OK, after talking with a fellow programmer we came up with the following using EXECSCRIPT which will do what you want...
OleDbConnection oConn = new OleDbConnection("provider=VFPOLEDB.1;data source='C:\\';password='';user id=''");
oConn.Open();
OleDbCommand oCom = new OleDbCommand("EXECSCRIPT('DO C:\\prog.prg')", oConn);
oCom.ExecuteNonQuery();

boyd.gif

SweetPotato Software Website
My Blog
 
You are one awsome dude!

Thanks a ton man for all your help, tell your buddy I said thanks too ;)
 
arg, unfortunatly im still having problems. Could you look and see what im doing wrong here?

Thanks

string program;
System.IO.File.Delete(@"C:\\rsprog.prg");
program = "Replace All Title with 'Title'";

System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\\rsprog.prg", true);

file.WriteLine(program);
file.Close();


OleDbConnection oConn = new OleDbConnection
("provider=VFPOLEDB.1;data source='C:\\Tester.dbf'");

oConn.Open();
OleDbCommand oCom = new OleDbCommand("EXECSCRIPT('DO C:\\rsprog.prg')", oConn);
oCom.ExecuteNonQuery();
 
Hi stathread,

Since you are creating the prg on the fly, why not ammend your code to use the appropriate table and then do the replace. Something like...

Use "tester.dbf" in 0 shared
Replace All Title with 'Title' in 'tester'

You wouldn't need to select the table in the connection and it should work. I haven't tested it though.

boyd.gif

SweetPotato Software Website
My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top