Foxtable(狐表)用户栏目专家坐堂 → 如何读出SQL字段中的SQL命令字符串并执行?


  共有4114人关注过本帖树形打印复制链接

主题:如何读出SQL字段中的SQL命令字符串并执行?

帅哥哟,离线,有人找我吗?
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:112380 积分:572162 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/10/29 8:39:00 [显示全部帖子]

方法1、。SQL改为这种:se1ect top 100 * fr0m ITEM  where item_code like '【_code_no】%'   order by item_code 
然后查询执行参考:
dim _no_id as string= "1"
dim dr as datarow = datatables("sql_sent").find("NO_ID=" & _no_id)
if dr isnot nothing then
dim _code_no as string = "xxx"
Dim cmd As New SQLCommand
cmd.ConnectionName = "数据源名称"
Dim
 dt As DataTable
cmd.CommandText = dr("
sent_A").replace("_code_no",_code_no)
dt = cmd.ExecuteReader()
end if

方法2,SQL改为这种:se1ect top 100 * fr0m ITEM  where item_code like ?   order by item_code 
然后查询执行参考:
dim _no_id as string= "1"
dim dr as datarow = datatables("sql_sent").find("NO_ID=" & _no_id)
if dr isnot nothing then
dim _code_no as string = "xxx" & "%"
Dim cmd As new SQLCommand
cmd
.ConnectionName = "数据源名称"
cmd
.CommandText = dr("sent_A")
cmd
.Parameters.Add("@code_no",_code_no)
Dim
 dt As DataTable = cmd.ExecuteReader()
end if

 回到顶部