SQL语句中变量替换方法

   在数据库连接时,经常用到SQL查询语言,比如select * from table1 where colum1=value . 
  
可以写成公用的函数来实现查询条件的变换:
   
   
' Replace all @n arguments with provided values.
'
此代码为转载: Francesco Balena
Function ReplaceParams(ByVal text As StringParamArray args() As Variant)
    
Dim i As Integer
    
For i = LBound(args) To UBound(args)
        text 
= Replace(text, "@" & Trim$(i + 1), args(i))
    
Next
    ReplaceParams 
= text
End Function

 

可以不必每次查询都要重新写一个SQL查询语句.

posted on 2008-03-30 21:38  风不止  阅读(1023)  评论(0)    收藏  举报

导航