求高人看这段SQL查询代码!!!!
我窗口中放了text控件,和cmdgo的按钮控件,想实现如下功能:输入牌号无误后,能够连接“碳素结构钢及优质碳素结构钢”数据库,访问“材料用途”表,把符合要求的结果显示到MSHFlexGrid中。Private Sub cmdgo_Click()
If Trim(Text1.Text) < 1 Then
MsgBox "牌号不能为空!", vbInformation
Text1 = ""
End If
Dim objcn As New ADODB.Connection
With objcn
.Provider = "SQLOLEDB"
.ConnectionString = "user ID=ls;PWD=123456;Data source=(local);" & _
"initial catalog=碳素结构钢及优质碳素结构钢"
.Open
End With
Dim rs1 As New ADODB.Recordset
rs1.Open "select * from 材料用途 where 牌号 like" & "'"& Text1.Text&"'", objcn, adOpenKeyset, adLockOptimistic
Set MSHFlexGrid1.DataSource = rs1
End Sub
运行后,红色那一行显示 编译错误,语法错误,但控件查询,按说应该就是这样啊,请高人指点!!