from子句语法错误,对象adodc1的方法refresh失败”..

来源:百度知道 编辑:UC知道 时间:2024/06/22 21:33:58
If Text1.Text = "" And Text2.Text = "" Then
MsgBox "请输入产品或工艺编号进行查找!", vbOKOnly, "提示"
Text1.SetFocus
Else
If Text1.Text <> "" And Text2.Text = "" Then
产品基础数据信息.Adodc1.RecordSource = "select * from 产品基础数据 where 产品编号= '" & Trim(Text1.Text) & "'"
产品基础数据信息.Adodc1.CommandType = adCmdText
产品基础数据信息.Adodc1.Refresh
产品基础数据信息.DataGrid1.Refresh
Unload Me
MsgBox "查找完毕!"
Else
If Text1.Text = "" And Text2.Text <> "" Then
产品基础数据信息.Adodc1.RecordSource = "select * from 产品基础数据 where 工序编号 = '" & Trim(Text2.Text) & "'"
产品基础数据信息.Adodc1.CommandType = adCmdTable
产品基础数据信息.Adodc1.Refresh
产品基础数据信息.DataGrid1.Refresh
Unload Me
MsgBox "查找完毕!"
Else
End If
End If

请高手帮忙看看
第一个查询可以运行啊 第二个查询就出错
from子句语法错误,对象adodc1的方法refresh失败”..

注意你的CommandType属性设置的区别,所以第一个可以,第二个错误。
第一个查询的:
产品基础数据信息.Adodc1.CommandType = adCmdText
第二个查询的:
产品基础数据信息.Adodc1.CommandType = adCmdTable

CommandType表示当前命令形式,adCmdText表示数据来自SQL语句查询结果,adCmdTable表示数据直接来自表,如果设置为该值,前面要改成:产品基础数据信息.Adodc1.RecordSource =表名
按你的代码,显然应该把第二个查询的CommandType改成adCmdText