1

我有一个需要导入到我的 Access 数据库中的 Excel 表。工作表如下所示:

日期 接收 面额 项目 N° 数量 RECUE
06/01/2010 DVD-欲望都市 PCR-PA21550167 5
06/01/2010 DVD-阿凡达娜蒂 2 PCR-PA21550209 10

然后我使用 adodb 将此文件传输到数据库中:


Dim rs2 As New ADODB.Recordset
Dim cnn2 As New ADODB.Connection
Dim cmd2 As New ADODB.Command
Dim intField As Integer
Dim strFile As String

strFile = fncOpenFile
If strFile = "" Then Exit Sub

With cnn2
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=" & strFile& "; " & "Extended Properties=Excel 8.0"
    .Open
End With

Set cmd2.ActiveConnection = cnn2
cmd2.CommandType = adCmdText
cmd2.CommandText = "SELECT * FROM [PCR$]"
rs2.CursorLocation = adUseClient
rs2.CursorType = adOpenDynamic
rs2.LockType = adLockOptimistic

rs2.Open cmd2

While Not rs2.EOF
        strNaam = rs2.Fields(3).Value
Loop

现在我的问题:某些字段中有文本。字段值应该是item0001,但据报道它是 NULL

当该字段具有常规数字时,它可以正常工作。

奇怪的是:工作表中还有其他文本字段,它们工作正常。

4

1 回答 1

4

在您的扩展属性部分更具体(并且不要在那里省略内部引号)。

特别是,尝试Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"允许混合数字和文本数据。

更多详细信息,请访问http://connectionstrings.com/

于 2010-01-14T16:51:21.457 回答