简体   繁体   English

SQL Server表到FoxPro表的问题

[英]SQL server table to FoxPro table issues

I am trying to get some SQL server tables into FoxPro dbf. 我正在尝试将一些SQL Server表插入FoxPro dbf。

I successfully managed to bcp export data such that when I use FoxPro Import Wizard, the data imports correctly. 我成功管理了bcp导出数据,以便当我使用FoxPro导入向导时,数据可以正确导入。 But when I try to do it at the command line, I can at best import the first few columns and all the other columns disappear. 但是,当我尝试在命令行上执行此操作时,我最多只能导入前几列,而其他所有列都将消失。

In the following directory, I put both the .CSV file and the successful DBF import table. 在以下目录中,我同时放置了.CSV文件和成功的DBF导入表。

directory with 2 files here 目录,其中有2个文件

What I need to figure out is how to import these CSV files from the command line in FoxPro. 我需要弄清楚的是如何从FoxPro的命令行中导入这些CSV文件。

I tried various combinations of; 我尝试了各种组合;

APPEND FROM D:\work\oh\output\sqloutput.csv TYPE CSV
APPEND FROM D:\work\oh\output\sqloutput.csv DELIMITED WITH TAB

None of it works. 没有一个有效。

Any ideas? 有任何想法吗? I know I have done this before, I don't remember what the trick was... 我知道我以前做过这个,我不记得那招是什么了...

Wow.. I think you are going about it the wrong way... Just do a simple SQLCONNECT() to the SQL Database, run a query to the data source, stored procedure, or whatever and it's in a cursor in VFP... Then, you can just "copy" to a DBF and you are done... Something like 哇。。我想您是用错误的方式来做的...只需对SQL数据库执行简单的SQLCONNECT(),对数据源,存储过程等执行查询,并且它位于VFP中的游标中。然后,您只需“复制”到DBF就可以了……

lnH = SQLCONNECT()

(dialog pops up for you of ODBC connections). (对话框为您弹出ODBC连接)。

if not that, you could do 如果不是那样,你可以做

lnH = SQLStringConnect("Provider=... for sql server, server name, etc")

Then 然后

if lnH > 0
   sqlexec( lnH, "select * from someTableOnServer where whateverConditon", "C_LocalCursor" )

   select C_LocalCursor
   copy to PermanentTable

   sqldisconnect( lnH )
endif 

Now, if there are columns that are longer than 10 character column names, and you are NOT using a database container, you might have to adjust by either changing the query to GET the column names, or re-select the data once local to fit into 10 character non-dbc table context. 现在,如果某些列的长度超过10个字符,并且您没有使用数据库容器,则可能必须进行调整,方法是将查询更改为GET列名,或者重新选择本地数据以适合转换成10个字符的非dbc表上下文。

Another example to build out the query could be -- for simplicity of readability while typing, I use text/endtext such as 建立查询的另一个示例可能是-为了简化键入时的可读性,我使用诸如

text to lcSQLCmd noshow pretext 1+2
   select
         t1.Column1,
         t1.AVeryLongColumnName as AVLColName,
         t1.AnotherLongColumn2  as ALC2,
         t1.SomeFlag,
         t2.ColumnFromAnotherTable as CFATbl,
         t2.AnotherCol
      from
         SQLDatabase.dbo.SQLTable1 t1
            join SQLDatabase.dbo.SQLTable2 t2
               on t1.SomeKey = t2.SomeKey
      where
         t1.SomeCriteria = 'whatever'
      order by
         t1.SomeFlag
endtext

*/ Then, to "clean up" the string for VFP to pass properly, 
*/ strip out the cr/lf from the text such as
lcSQLCmd = chrtran( lcSQLCmd, chr(13)+chr(10), "" )

*/ THEN, pass this command through sqlexec()
sqlexec( lnH, lcSQLCmd, "C_LocalCursor" )

The second is obviously MUCH easier to read what you are trying to get, and notice I've also pre-shortened the long column names to VFP 10 char non-DBC column name limit. 第二个显然是很容易阅读您要获取的内容,并且请注意,我也将长列名预先缩短为VFP 10 char non-DBC列名限制。 Then, just copy out like the first example. 然后,像第一个示例一样复制出来。

Are all of the fields in the receiving FoxPro table in the same order and the same data type as the columns in the CSV which you are trying to add into it? 接收FoxPro表中的所有字段是否都与您要添加到其中的CSV中的列的顺序和数据类型相同? Are they all big enough to cope with the data? 它们都足够大以应付数据吗? Have you ensured that none of the text fields in the CSV contain the field delimiter within their text? 您是否确保CSV中的所有文本字段在其文本中都不包含字段定界符?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM