以文本方式查看主题
- Foxtable(狐表) (http://foxtable.net/bbs/index.asp)
-- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2)
---- 加载问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=187527)
|
-- 作者:lin98
-- 发布时间:2023/7/24 10:07:00
-- 加载问题
加载问题 如何将代码一和代码二,能否合并一条SQ-L语句,如何实现{表A}和{表B}合并后,按日期、制单人、UserID加载数据? 注:1.原始表有三张,分别表A}、{表B}、{Users} 2.{Users}表的字段,分别UserID、制单人、Xjry。 3.表1是窗口上的表名
代码一 Selec-t {表B}.单号,{表B}.制单人,料号,料名,数量,{表B}.备注,{表B}.用户ID,审核,选中,客户,日期 From ({表B} Inner JOIN {表A} ON {表A}.[单号] = {表B}.[单号]) Where 选中=true
代码二 Dim StartDate As Date Dim EndDate As Date Dim Filter As String = "制单人=\'" & _Username & "\' and 日期 >= #" & StartDate & "# And 日期 <= #" & EndDate & "# " Dim dr2 As DataRow dr2 = DataTables("Users").Find("[Group] = \'" & _UserGroup & "\'") Dim s As String If dr2 IsNot Nothing Then s = dr2("Xjry") If s > "" Then Filter = Filter & " or UserID in (" & s.Replace(",", ",") & ")" End If End If DataTables("表1").LoadFilter = Filter \' DataTables("表1").Load()
|
-- 作者:有点蓝
-- 发布时间:2023/7/24 10:12:00
--
Dim StartDate As Date Dim EndDate As Date Dim Filter As String = "制单人=\'" & _Username & "\' and 日期 >= #" & StartDate & "# And 日期 <= #" & EndDate & "# " Dim dr2 As DataRow dr2 = DataTables("Users").Find("[Group] = \'" & _UserGroup & "\'") Dim s As String If dr2 IsNot Nothing Then s = dr2("Xjry") If s > "" Then Filter = Filter & " or UserID in (" & s.Replace(",", ",") & ")" End If End If Dim cmd As New SQLCommand cmd.ConnectionName = "数据源名称" Dim dt As DataTable cmd.CommandText = "Selec-t {表B}.单号,{表B}.制单人,料号,料名,数量,{表B}.备注,{表B}.用户ID,审核,选中,客户,日期 From ({表B} Inner JOIN {表A} ON {表A}.[单号] = {表B}.[单号]) Where 选中=true and " & Filter Tables("表1")。DataSource = cmd.ExecuteReader()
|
-- 作者:lin98
-- 发布时间:2023/7/24 12:41:00
--
Dim StartDate As Date Dim EndDate As Date Dim Filter As String = "制单人=\'" & _Username & "\' and 日期 >= #" & StartDate & "# And 日期 <= #" & EndDate & "# " Dim dr2 As DataRow dr2 = DataTables("Users").Find("[Group] = \'" & _UserGroup & "\'") Dim s As String If dr2 IsNot Nothing Then s = dr2("Xjry") If s > "" Then Filter = Filter & " or UserID in (" & s.Replace(",", ",") & ")" End If End If Dim cmd As New SQLCommand cmd.ConnectionName = "Sale" Dim dt As DataTable cmd.CommandText = "Selec-t {表B}.单号,{表B}.制单人,料号,料名,数量,{表B}.备注,{表B}.用户ID,审核,选中,客户,日期 From ({表B} Inner JOIN {表A} ON {表A}.[单号] = {表B}.[单号]) Where 选中=true and " & Filter Tables("合并查询_Table1")。DataSource = cmd.ExecuteReader() |
执行后,报错 .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2022.8.18.1 错误所在事件: 详细错误信息: 该特定字段 \'制单人\' 可以参考 SQL 语句中 FROM 子句列表中的多个表。
[此贴子已经被作者于2023/7/24 12:41:20编辑过]
|
-- 作者:有点蓝
-- 发布时间:2023/7/24 13:33:00
--
指定是哪个表的列
Dim Filter As String = "{表B}.制单人=\'" & _Username & "\' and 日期 >= #
|
-- 作者:lin98
-- 发布时间:2023/7/24 16:06:00
--
\'e.Form.Controls("StartDate").Value = New Date(Date.today.Year, Date.today.Month, 1) \'e.Form.Controls("EndDate").Value = New Date(Date.today.Year, Date.today.Month, Date.DaysInMonth(Date.today.Year, Date.today.Month))
\'Dim StartDate As Date \'Dim EndDate As Date
\'\'Dim Filter As String = "{表B}.制单人=\'" & _Username & "\' and {表A}.日期 >= #" & StartDate & "# And {表A}.日期 <= #" & EndDate & "# " \'\'Dim Filter As String = "{表B}.制单人=\'" & _Username & "\' and 日期 >= #" & StartDate & "# And 日期 <= #" & EndDate & "# "
报错 .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2022.8.18.1 错误所在事件: 详细错误信息: 至少一个参数没有被指定值。
|
-- 作者:有点蓝
-- 发布时间:2023/7/24 16:08:00
--
什么数据库、弹出合并后完整的sql看看
|
-- 作者:lin98
-- 发布时间:2023/7/24 16:46:00
--
ACCESS数据库,完整代码
问题一: Dim StartDate As Date Dim EndDate As Date Dim Filter As String = "{表B}.制单人=\'" & _Username & "\' and 日期 >= #" & StartDate & "# And 日期 <= #" & EndDate & "# " Dim dr2 As DataRow dr2 = DataTables("Users").Find("[Group] = \'" & _UserGroup & "\'") Dim s As String If dr2 IsNot Nothing Then s = dr2("Xjry") If s > "" Then Filter = Filter & " or UserID in (" & s.Replace(",", ",") & ")" End If End If Dim cmd As New SQLCommand cmd.ConnectionName = "Sale" Dim dt As DataTable cmd.CommandText = "Selec-t {表B}.单号,{表B}.制单人,料号,料名,数量,{表B}.备注,{表B}.用户ID,审核,选中,客户,日期 From ({表B} Inner JOIN {表A} ON {表A}.[单号] = {表B}.[单号]) Where 选中=true and " & Filter Tables("合并查询_Table1")。DataSource = cmd.ExecuteReader()
报错 .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2022.8.18.1 错误所在事件: 详细错误信息: 至少一个参数没有被指定值。
问题二。黄色代码去掉日期,红字代码失效
注:1.原始表有三张,分别表A}、{表B}、{Users} 2.{Users}表的字段,分别UserID、制单人、Xjry。 |
|
[此贴子已经被作者于2023/7/24 16:48:46编辑过]
|
-- 作者:有点蓝
-- 发布时间:2023/7/24 16:49:00
--
cmd.CommandText = "Selec-t {表B}.单号,{表B}.制单人,料号,料名,数量,{表B}.备注,{表B}.用户ID,审核,选中,客户,日期 From ({表B} Inner JOIN {表A} ON {表A}.[单号] = {表B}.[单号]) Where 选中=true and " & Filter msgbox(cmd.CommandText)弹出合并后完整的sql看看
|
-- 作者:lin98
-- 发布时间:2023/7/24 16:56:00
--
此主题相关图片如下:合并表.jpg
|
-- 作者:有点蓝
-- 发布时间:2023/7/24 17:04:00
--
判断一下是否为空,在添加到条件里
|