Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行时错误'-2147217900'(80040e14)':在excel vba的sql查询中使用where时发生自动错误_Sql_Excel_Vba - Fatal编程技术网

运行时错误'-2147217900'(80040e14)':在excel vba的sql查询中使用where时发生自动错误

运行时错误'-2147217900'(80040e14)':在excel vba的sql查询中使用where时发生自动错误,sql,excel,vba,Sql,Excel,Vba,由于我对数据库不太了解,所以我正试图使用从某个论坛例程复制的以下内容从excel vba连接到我的SQLServerExpress 2005。它工作得很好。一旦我在sqlquery变量中使用WHERE,我就会得到双引号和单引号 运行时错误'-2147217900'80040e14': 自动化误差 从其他人身上提取数据的类似程序。我非常感谢你的帮助 谢谢 子连接测试 ' Create a connection object. Dim cnPubs As ADODB.Connection Set c

由于我对数据库不太了解,所以我正试图使用从某个论坛例程复制的以下内容从excel vba连接到我的SQLServerExpress 2005。它工作得很好。一旦我在sqlquery变量中使用WHERE,我就会得到双引号和单引号

运行时错误'-2147217900'80040e14': 自动化误差

从其他人身上提取数据的类似程序。我非常感谢你的帮助

谢谢

子连接测试

' Create a connection object.
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
Dim sqlquery As String
Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset

' Provide the connection string.
Dim strConn As String

'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB;"

sqlquery = "SELECT * FROM [Logisuite].[dbo].[EoWebStatus]"

'Connect to the Pubs database on the local server.
strConn = strConn & "Server=SERVITRANSMAIn\SQLEXPRESS;Database=logisuite;Trusted_Connection=True;"

'Use an integrated login.
strConn = strConn & "INTEGRATED SECURITY=sspi;"

'Now open the connection.
cnPubs.Open strConn

' Create a recordset object.
Set rsPubs = New ADODB.Recordset

With rsPubs
    ' Assign the Connection object.
    .ActiveConnection = cnPubs
    ' Extract the required records.
    .Open sqlquery
    ' Copy the records into cell A1 on Sheet1.
    Sheet1.Range("A1").CopyFromRecordset rsPubs

    ' Tidy up
    .Close
End With

cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing

End Sub

显示不起作用的代码,并指出导致错误的行。我99%确定是查询导致了自动错误。显示您的WHERE查询!非常感谢各位回答下面的完整查询:sqlquery=SELECT*FROM[Logisuite].[dbo].[EoWebStatus]&WHERE[UpdateBy]=&Chr$39&dennisk&Chr$39,导致错误的行是。在with end with中打开sqlquery以补充我在即时窗口中打印sqlquery变量时的上一篇文章。输出如下:从[Logisuite].[dbo].[EoWebStatus]中选择*其中[UpdateBy]='dennisk'显然是正确的。再补充一句,我甚至不能使用order by。。。。。除了从事物中选择之外,什么都没有