Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL pass-thru, SQL Server called from VFP
Message
From
15/09/2004 09:46:30
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
15/09/2004 09:24:25
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00942357
Message ID:
00942371
Views:
30
This message has been marked as a message which has helped to the initial question of the thread.
>Hi,
> I am calling SQL Server from VFP8 with SQL pass-through. I have a foxpro table that I need to copy into SQL server. Is there a way of doing this quickly? Or do I need to copy the record row by row?
>
>HIA,
>Beth

If you mean an SQLExec generated cursor make your cursor updatable and Tableupdate.
If you mean to copy a native VFP table to SQL table use either OpenRowSet or bulk/copy.
ie:
Local lnHandle, lcDatabaseName
lcDatabaseName = "myBulkTest"

lnHandle=Sqlstringconnect('DRIVER=SQL Server;SERVER=server;Trusted_connection=Yes')
If SQLExec(lnHandle, "create database "+lcDatabaseName) < 0
  Do errHand
  Return
Endif


mySQLExec(lnHandle, "use "+lcDatabaseName)
mySQLExec(lnHandle, ;
  " create table myTable"+;
  "   (line_no int not null,"+;
  "    order_id int not null,"+;
  "    product_id int not null,"+;
  "    unit_price smallmoney not null,"+;
  "    quantity int not null)" )

mySQLExec(lnHandle, ;
  "insert into myTable"+;
  "   SELECT * "+;
  "   FROM OPENROWSET('VFPOLEDB', "+;
  "   '"+_samples+"data\testdata.dbc';'';'',"+;
  "   'select * from orditems') " )

mySQLExec(lnHandle, "select * from myTable", "myBulk")

SQLDisconnect(lnHandle)

Select myBulk
Browse

Function mySQLExec
Lparameters tnHandle, tcSQL, tcCursorName
tcCursorName = Iif(Empty(tcCursorName),'',tcCursorName)
If SQLExec(tnHandle,tcSQL,tcCursorName) < 0
  Do errHand With tcSQL
Endif

Function errHand
Lparameters tcSQL
lcError=tcSQL+Chr(13)
Aerror(arrCheck)
For ix=1 To 7
  lcError = lcError+Trans( arrCheck [ix])+ Chr(13)
Endfor
Messagebox(lcError,0,'Error def.')
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform