从子句- VB6中出现语法错误

时间:2021-03-30 15:43:15

Having a problem getting the above Error Message. Can anyone assist please ?

在获取上述错误消息时出现问题。有人能帮忙吗?

Dim cn As New ADODB.Connection 
Dim cmd As New ADODB.Command 
Dim RS As New ADODB.Recordset 
Dim RS2 As New ADODB.Recordset

Set cn = New ADODB.Connection
Call cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & TheServer &   
          FileTypeOld & ";" & "Jet OLEDB:Database Password=12345678;")

If cn.State = 0 Then cn.Open
Set cmd.ActiveConnection = cn
cmd.CommandText = "SELECT * FROM mov"
cmd.CommandType = adCmdTable
Set RS = cmd.Execute

2 个解决方案

#1


1  

The problem is you are using an SQL statement with a Command type adCmdTable. When using that command type, ADO will generate the select query internally, you are expected in this case to just specify the name of the table.

问题是您正在使用一个带有命令类型adCmdTable的SQL语句。当使用该命令类型时,ADO将在内部生成select查询,在这种情况下,只需要指定表的名称。

Alternatively, just remove the cmd.CommandType = adCmdTable line all together and keep the select * syntax.

或者,只需删除cmd。CommandType = adCmdTable行集合在一起,并保留select *语法。

#2


1  

You need ton add this character _ which is underscore at the end of this line

您需要在本行末尾添加这个__字符

Just replace with this:

只是替换为:

Call cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & TheServer & _
FileTypeOld & ";" & "Jet OLEDB:Database Password=12345678;")

or you can merge both lines into one line without underscore, just like this

或者你可以把这两行合并成一行,没有下划线,就像这样

Call cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & TheServer & ileTypeOld & ";" & "Jet OLEDB:Database Password=12345678;")

#1


1  

The problem is you are using an SQL statement with a Command type adCmdTable. When using that command type, ADO will generate the select query internally, you are expected in this case to just specify the name of the table.

问题是您正在使用一个带有命令类型adCmdTable的SQL语句。当使用该命令类型时,ADO将在内部生成select查询,在这种情况下,只需要指定表的名称。

Alternatively, just remove the cmd.CommandType = adCmdTable line all together and keep the select * syntax.

或者,只需删除cmd。CommandType = adCmdTable行集合在一起,并保留select *语法。

#2


1  

You need ton add this character _ which is underscore at the end of this line

您需要在本行末尾添加这个__字符

Just replace with this:

只是替换为:

Call cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & TheServer & _
FileTypeOld & ";" & "Jet OLEDB:Database Password=12345678;")

or you can merge both lines into one line without underscore, just like this

或者你可以把这两行合并成一行,没有下划线,就像这样

Call cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & TheServer & ileTypeOld & ";" & "Jet OLEDB:Database Password=12345678;")