求助:sql如何适用宏替换?
Dim aaa As String
aaa = Trim(TextBox1.Value)
MsgBox "参保人员为 " & Format(aaa) & " ", vbOKOnly + vbInformation, "信息提示"
Set cnn = CreateObject("ADODB.connection")
cnn.connectionstring = "Driver={SQL Server};server=shbx;uid=sa;pwd=sa;database=cqgls"
cnn.Open
Set rs = cnn.Execute("Select * from t01_05 where t0105 like ('+aaa+')") '查询不到记录
如改成 Set rs = cnn.Execute("Select * from t01_05 where t0105 like ('张三')") '完全能查询到记录
什么"+ 字符串=";"% 字符串%" 都用过,还是不行。
If Not rs.EOF Then
rs.movefirst
i = 3
j = 0
While Not rs.EOF
' If Trim(Rs(15).Value) = Trim(TextBox1.Value) Then
'For j = 0 To Rs.Fields.Count - 1
Cells(i, 2).Value = Trim(rs(7).Value)
Cells(i, 3).Value = Trim(rs(13).Value)
Cells(i, 4).Value = Trim(rs(14).Value)
Cells(i, 5).Value = rs(15).Value
Cells(i, 6).Value = rs(16).Value
Cells(i, 7).Value = rs(17).Value
Cells(i, 8).Value = rs(18).Value
rs.MoveNext
i = i + 1
Wend
Else
MsgBox "没有符合符合条件的记录", vbOKOnly + vbInformation, "检测"
End If
cnn.Close
Set cnn = Nothing
Set rs = Nothing