【发布时间】:2016-02-17 23:35:32
【问题描述】:
我正在尝试加入两个 CSV 文件。 目前我正在尝试添加以下代码。如果使用“If Not objConnection Is Nothing Then”打开连接,我添加了一个验证,但据说连接是打开的。当我运行代码时,我收到以下错误消息:
大致翻译为:
执行时间出现错误“2147217904 (80040e10)”:
一些必需的值没有指定。
我加载了以下库:
代码如下:
Dim objConnection As ADODB.Connection
Dim objrecordset As ADODB.Recordset
fNameAndPath = Application.GetOpenFilename(FileFilter:="CSV File (*.csv),(*.csv)", Title:="Select first CSV file")
If fNameAndPath = False Then
Exit Sub
End If
fNameAndPath2 = Application.GetOpenFilename(FileFilter:="CSV File (*.csv),(*.csv)", Title:="Select second CSV file")
If fNameAndPath2 = False Then
Exit Sub
End If
Set objConnection = CreateObject("ADODB.Connection")
Set objrecordset = CreateObject("ADODB.Recordset")
strPath = Left(fNameAndPath, InStrRev(fNameAndPath, "\") - 1)
Filename = Mid(fNameAndPath, InStrRev(fNameAndPath, "\") + 1)
strPath2 = Left(fNameAndPath2, InStrRev(fNameAndPath2, "\") - 1)
Filename2 = Mid(fNameAndPath2, InStrRev(fNameAndPath2, "\") + 1)
With objConnection
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & strPath & _
";Extended Properties=""text;HDR=Yes;FMT=Delimited"";"
.Open
End With
strSql = "SELECT * FROM " & Filename & " as file1, " _
& "" & Filename2 & " as file2" _
& " WHERE file1.[APOYO] = file2.[APOYO]"
If Not objConnection Is Nothing Then
If (objConnection.State And adStateOpen) = adStateOpen Then
Set objrecordset = objConnection.Execute(strSql)
End If
End If
【问题讨论】:
-
需要打开一个select语句,执行INSERT/UPDATE等 set objRS = new adodb.recordset:objRS.open strSQL,objConn
-
Set objConnection = CreateObject("ADODB.Connection") Set objrecordset = CreateObject("ADODB.Recordset") 这可以通过 set x=new y 来完成,你已经设置了类型跨度>
-
谢谢!我也尝试过开放式方法
-
你试过ado 2.8吗?我认为您可能需要将文件名放在 ' 中,例如 'c:\test\test.xls'!DataSheet,因此该工作表就像来自 myexcel 的传统选择 * 中的表格。我还记得工作表上的美元前缀.....看看 www.connectionstrings.com
-
是的,试过了。它是一个 CSV 文件,而不是 xlsx 或 xls