My question is pretty much the exact same as Efficient way to bulk insert into Dbase (.dbf) files - Is there an efficient way to bulk insert into dbase IV dbf files? The source data is coming from SQL Server 2012. I have Visual FoxPro available but I'd like to do this programatically from C#.
问题:
回答1:
As mentioned in comment, if in VFP, you should be able to do quite easily by means of
nHandle = sqlconnect( "connection string to your database" )
sqlexec( nHandle, "select * from YourTable", "localResultSetInVFP" )
*/ At this point, the current work area is the "localResultSetInVFP"
copy to SomeOtherTable <== this actually creates the final DBF for you locally.
The only other way I can think of that MAY work is as follows.
Create a database CONTAINER in VFP.
Create a connection to the SQL Database.
Create a REMOTE VIEW to the table(s) in the SQL Database.
Then, in C# using the VFP OleDB, create a connection to the path AND include the .DBC database name. Then you might be able to do a select based on the VIEW name... and hopefully the .DBC will kick in, and open / get SQL connection handle, run the remote view query and return all the data to you.
Let me know if this guidance works for you.
One example to create table from existing within VFP's OleDB this also a simple "Create Table" command.
Example of simple insert-into with parameters to help prevent SQL-injection
a very good sample of build the command and parameters ONCE, then do for each row and execute to insert
Another that shows both insert AND update build context samples
Hopefully the above links show you a wide variety to implement creating and inserting into DBF files.
You can create whatever query from other database connection such as SQL, MySQL, etc and use a datareader or dataadapter.fill to download from one, loop into the VFP cycle insert and update the parameters... You'll see the examples and hopefully most are clear to follow.