在VB中如何执行动态SQL语句
在SQL中,当表名为变量时,可以使用动态语句,比如: declare @a nvarchar(55)
set @a= 'BA_BAZLFL'
exec('select * from ' +@a+ '')
这几个语句同时执行,可以达到和'select * from BA_BAZLFL’一样的效果。
如何通过VB来执行这段动态语句呢?
2016-11-23 15:52

2016-11-23 16:12
2016-11-23 21:47
2016-11-23 23:34
2016-11-24 09:00
程序代码:
dim tableName as string
dim strSql as string
tableName = "username"
strSql = "select * from " & tableName
set rs = conn.Execute(strSql)
2016-11-24 16:54
2016-11-24 21:30
2016-11-26 21:51