vbscript将访问查询导出到制表符分隔文件不起作用

时间:2023-01-16 19:55:40

I have this code:

我有这个代码:

db = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\baywotch.db5"
TextExportFile = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\Exp.txt"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open _
   "Provider = Microsoft.Jet.OLEDB.4.0; " & _
   "Data Source =" & db

strSQL = "SELECT * FROM tblAuction1"

rs.Open strSQL, cn, 3, 3

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.CreateTextFile(TextExportFile, True)

a = rs.GetString

f.WriteLine a

f.Close

Which is meant to connect to an access database and produce a tab delimited text file. tblAuction1 is a query in the database, and definitly exists and is not misspelt in any way, but I get an error that it cannot be found or does not exist. When I change it to tblAuction which is the name of the table, I get an error stating f.WriteLine a has been called incorrectly.

这意味着连接到访问数据库并生成制表符分隔的文本文件。 tblAuction1是数据库中的一个查询,并且绝对存在并且不会以任何方式拼错,但是我收到一个无法找到或不存在的错误。当我将它更改为tblAuction时,这是表的名称,我收到一个错误,指出f.WriteLine a被错误地调用。

edit: I now only get a problem with f.writeline a, saying an incorrect argument has been supplied. I no longer have a problem with tblAuction1

编辑:我现在只遇到f.writeline a的问题,说已经提供了错误的参数。我不再遇到tblAuction1的问题

edit: the sql code used for my query:

编辑:用于我的查询的sql代码:

SELECT tblAuction.article_no, tblAuction.article_name, tblAuction.subtitle, tblAuction.current_bid, tblAuction.start_price, tblAuction.bid_count, tblAuction.quant_total, tblAuction.quant_sold, tblAuction.start, tblAuction.ends, tblAuction.origin_end, tblUser.user_name, tblAuction.best_bidder_id, tblAuction.finished, tblAuction.watch, tblAuction.buyitnow_price, tblAuction.pic_url, tblAuction.private_auction, tblAuction.auction_type, tblAuction.insert_date, tblAuction.update_date, tblAuction.cat_1_id, tblAuction.cat_2_id, tblAuction.article_desc, tblAuction.countrycode, tblAuction.location, tblAuction.condition, tblAuction.revised, tblAuction.paypal_accept, tblAuction.pre_terminated, tblAuction.shipping_to, tblAuction.fee_insertion, tblAuction.fee_final, tblAuction.fee_listing, tblAuction.pic_xxl, tblAuction.pic_diashow, tblAuction.pic_count, tblAuction.item_site_id
FROM tblUser INNER JOIN tblAuction ON tblUser.id = tblAuction.seller_id;

3 个解决方案

#1


2  

I have tried to reproduce this on several databases and machines, I can't get your code to fail.

我试图在几个数据库和机器上重现这一点,我无法让你的代码失败。

Leaves :

  • a corrupt database, could you please run repair and try again ?
  • 一个腐败的数据库,请你运行修复,然后再试一次?

  • Fields in your database that are throwing of the query, I have tried several possibilities but can't find anything that brakes your code. To exclude other things you could try to create a new table and see if your code works on that table.
  • 数据库中抛出查询的字段,我已经尝试了几种可能性,但找不到任何可以制动代码的东西。要排除其他内容,您可以尝试创建一个新表,并查看您的代码是否适用于该表。

  • something wrong with your dll's , could you try it on another machine.
  • 你的dll有问题,你可以在另一台机器上试试吗?

Answer (to see how we came to the answer see the comments)

回答(看看我们如何得到答案看到评论)

There are unicode characters in your database that writeline does not accept because you created the textfile as ASCI.The characters in this case specifically where ♥♥♥

你的数据库中有unicode字符,其中writeline不接受,因为你创建了文本文件作为ASCI。在这种情况下的字符特别是♥♥♥

To make it work:

为了使它工作:

Set f = fs.CreateTextFile(TextExportFile, True, True)

P.S.

This question was answered earlier using the transfertext macro here As Remou points out this looks like a cleaner solution. To make it work with non-default delimiters is a bit of a pain. First start exporting the query you like to export by right clicking and choose export. In the following dialogs specify the specifications and save these. When creating the macro select the specifications you just saved.

这个问题早些时候使用transfertext宏回答了。正如Remou指出这看起来像一个更清洁的解决方案。使其适用于非默认分隔符有点痛苦。首先通过右键单击开始导出要导出的查询,然后选择导出。在以下对话框中指定规范并保存这些规范。创建宏时,请选择刚刚保存的规格。

#2


0  

I think there is something wrong with the spaces in your connection string

我认为你的连接字符串中的空格有问题

Try this:

cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = db
cn.Open

HTH

Update: Maybe there is a problem with the access rights to the database? Or the mdb is already opened exclusively by another user (You with your access in design mode)?

更新:可能是数据库访问权限有问题?或者mdb已经由另一个用户独占打开(您在设计模式下具有访问权限)?

#3


0  

Try this


cn.Open _
  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Persist Security Info=False;" & _
  "Data Source=" & db

#1


2  

I have tried to reproduce this on several databases and machines, I can't get your code to fail.

我试图在几个数据库和机器上重现这一点,我无法让你的代码失败。

Leaves :

  • a corrupt database, could you please run repair and try again ?
  • 一个腐败的数据库,请你运行修复,然后再试一次?

  • Fields in your database that are throwing of the query, I have tried several possibilities but can't find anything that brakes your code. To exclude other things you could try to create a new table and see if your code works on that table.
  • 数据库中抛出查询的字段,我已经尝试了几种可能性,但找不到任何可以制动代码的东西。要排除其他内容,您可以尝试创建一个新表,并查看您的代码是否适用于该表。

  • something wrong with your dll's , could you try it on another machine.
  • 你的dll有问题,你可以在另一台机器上试试吗?

Answer (to see how we came to the answer see the comments)

回答(看看我们如何得到答案看到评论)

There are unicode characters in your database that writeline does not accept because you created the textfile as ASCI.The characters in this case specifically where ♥♥♥

你的数据库中有unicode字符,其中writeline不接受,因为你创建了文本文件作为ASCI。在这种情况下的字符特别是♥♥♥

To make it work:

为了使它工作:

Set f = fs.CreateTextFile(TextExportFile, True, True)

P.S.

This question was answered earlier using the transfertext macro here As Remou points out this looks like a cleaner solution. To make it work with non-default delimiters is a bit of a pain. First start exporting the query you like to export by right clicking and choose export. In the following dialogs specify the specifications and save these. When creating the macro select the specifications you just saved.

这个问题早些时候使用transfertext宏回答了。正如Remou指出这看起来像一个更清洁的解决方案。使其适用于非默认分隔符有点痛苦。首先通过右键单击开始导出要导出的查询,然后选择导出。在以下对话框中指定规范并保存这些规范。创建宏时,请选择刚刚保存的规格。

#2


0  

I think there is something wrong with the spaces in your connection string

我认为你的连接字符串中的空格有问题

Try this:

cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = db
cn.Open

HTH

Update: Maybe there is a problem with the access rights to the database? Or the mdb is already opened exclusively by another user (You with your access in design mode)?

更新:可能是数据库访问权限有问题?或者mdb已经由另一个用户独占打开(您在设计模式下具有访问权限)?

#3


0  

Try this


cn.Open _
  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Persist Security Info=False;" & _
  "Data Source=" & db