VB中sql语句的拼接
VB中的sql语句如下:
Dim strSql As String = "select * from " & tableName & " where " & codeRowName & " like '%" & mark & DateTime.Now.ToString("yyyyMMdd") & "%'"
其中tableName、codeRowName、mark 是函数带的参数,已放到语句中。
(
tableName:Clients
codeRowName:ClientCode
mark :W
)
但DateTime.Now.ToString("yyyyMMdd")这句怎么放到语句里面?
我拼接的语句是: select * from Clients where ClientCode like '%W%'
还有DateTime.Now.ToString("yyyyMMdd")没放进去。怎么解决?完整的语句应该是什么?
------解决方案--------------------
看了好久 没发现你的有问题 刚才测试了下 也Ok的
测试代码如下
VB code
Module Module1
Sub Main()
Dim tableName As String = "Clients"
Dim codeRowName As String = "ClientCode"
Dim mark As String = "W"
Dim strSql As String = "select * from " & tableName & " where " & codeRowName & " like '%" & mark & DateTime.Now.ToString("yyyyMMdd") & "%'"
System.Console.WriteLine(strSql)
System.Console.Read()
End Sub
End Module