0

我有输入线,如 -

001-407600 12/26/2011 04:25:43.250 12/26/2011 04:25:43.156
001-338000 12/26/2011 04:22:49.250 12/26/2011 04:22:49.156
001-51600 12/26/2011 04:10:53.234 12/26/2011 04:10:53.140
001-351900 12/26/2011 04:23:24.000 12/26/2011 04:23:23.906

我想通过使用VB脚本将这些数据分别写入DATATABLE具有列名的表中jobid date1 time1 date2 time2

请建议我该怎么做。

4

1 回答 1

1

我不太确定文本文件的格式,因此您可能必须使用FIELDTERMINATORand ROWTERMINATOR,但这种方法比尝试逐行执行此方法更容易、更有效。

set conn = createobject("ADODB.Connection")

connstr = "Provider=SQLNCLI;Data Source=server\instance;User ID=username;" & _
          "Password=password;Initial Catalog=database_name;"

conn.open connstr

filepath = "c:\wherever\whatever.txt"

sql = "BULK INSERT dbo.DATATABLE FROM '" & filepath & "'" & _
      " WITH (ROWTERMINATOR = '\r\n', FIELDTERMINATOR = ' ');"

conn.execute sql,,129

conn.close : set conn = nothing
于 2012-07-17T12:15:02.203 回答