Vb.net 如何解决系统错误&;excel ADOB连接中的H80040E14(-2147217900)
我试图通过excel从SQL数据库获取数据,我使用的是ADOB连接。这是工作正常,现在我得到了一个运行时错误,不知道是什么原因。我没有更改代码。我的以下代码是:Vb.net 如何解决系统错误&;excel ADOB连接中的H80040E14(-2147217900),vb.net,excel,ado,sqlconnection,vba,Vb.net,Excel,Ado,Sqlconnection,Vba,我试图通过excel从SQL数据库获取数据,我使用的是ADOB连接。这是工作正常,现在我得到了一个运行时错误,不知道是什么原因。我没有更改代码。我的以下代码是: Public Sub SQL_Connection() Dim con As ADODB.Connection Dim rs As ADODB.Recordset Dim StrQuery As String Set con = New ADODB.Connection Set rs =
Public Sub SQL_Connection()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrQuery As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
With ActiveSheet()
.Unprotect Password:=*****
End With
Sheets(2).Range("A2:H2").ClearContents
........
If CheckBox4.Value = True Then
strCon = "Provider=SQLOLEDB;Data Source=******\SQLEXPRESS;" & _
"Initial Catalog=testdata;" & _
"User ID=test;Password=*****;"
End If
........
If CheckBox4.Value = True Then
Const DB_CONNECT_STRING = "Provider=SQLOLEDB;Data Source=******\SQLEXPRESS;Initial Catalog=testdata;user id ='test';password=*****"
Set myConn = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command")
myConn.ConnectionTimeout = 15
myConn.Open DB_CONNECT_STRING1
Set myCommand.ActiveConnection = myConn
myCommand.CommandText = "UPDATE Rewind SET Cause = '" & Sheets(2).Range("I2") & "' WHERE RewindID = '" & Sheets(2).Range("J2") & "'"
myCommand.Execute
myConn.Close
End If
With ActiveSheet
.Protect Password:=66090
End With
End Sub
请帮忙 如果您注释掉
myCommand.Execute
行,它是否仍然出错?这表明错误在您的CommandText
I2和J2是否包含有效值?特别是其中是否有撇号?@CLR:I厌倦了注释,但在运行时仍然会出现系统错误。根据Microsoft的说法,错误本身意味着:查询使用非ANSI外部联接运算符(“=”或“=”)-虽然我们可以看到您发送的查询中没有联接。Microsoft声明修复程序将停止使用非ANSI联接,或将数据库的版本号恢复到80或之前。如果在未运行SQL命令的情况下出现错误,然后它会提示连接字符串DB\u CONNECT\u string
有问题-可能数据库不再与它兼容。