| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 632 人关注过本帖
标题:VB数据库中一个难点,请大家帮忙!
只看楼主 加入收藏
hmok
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-5-17
收藏
 问题点数:0 回复次数:5 
VB数据库中一个难点,请大家帮忙!
我用ADODC+DATAGRID建立了一个ACCESE的连接,数据很顺利的读到了DATAGRID中,但是因为需要还要再次对其内容进行筛选,而且无法在ADODC的SQL命令中添加了,因为SQL的命令已经很多了,再次添家VB会出错退出.有什么办法对保存在DATAGRID中的数据进行筛选或者干脆用满足某一条件就删除掉也行,但是前提是不能对数据库进行写操作,所以临时表的方法也不行.能帮我想想吗?



现在发送的SQL命令如下,就是让大家看看这个SQL有多复杂,没办法再用SQL命令去进行筛选了:
strsql1 = "SELECT   t_b_Consumer.f_ConsumerId AS 编号,t_b_Consumer.f_ConsumerName AS 姓名,t_b_Group.f_GroupName AS 部门,Dateserial(Datepart('yyyy','" & 考勤开始日期 & "'),Datepart('m','" & 考勤开始日期 & "'),"
strsql1 = strsql1 & "  Datepart('d','" & 考勤开始日期 & "')) AS 日期,(SELECT TOP 1 t_d_CardRecord.f_ReadDate"
strsql1 = strsql1 & "  FROM   t_d_CardRecord"
strsql1 = strsql1 & "   WHERE  ((t_b_Consumer.f_ConsumerId = t_d_CardRecord.f_ConsumerId"
strsql1 = strsql1 & "                                      AND (Datediff('d','" & 考勤开始日期 & "',[t_d_CardRecord].[f_ReadDate])) = 0)"
strsql1 = strsql1 & "                                                                                                                                                                AND ((Datediff('n',' " & 上午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                             Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                             Datepart('s',[t_d_CardRecord].[f_ReadDate])))) >=-  " & 上午刷卡提前 & ""
strsql1 = strsql1 & "                                                                                                                                                                     AND (Datediff('n',' " & 上午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                 Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                 Datepart('s',[t_d_CardRecord].[f_ReadDate])))) <=  " & 上午刷卡延后 & "))) AS 上午刷卡,Iif(Isnull(上午刷卡),'未刷卡',Iif((Datediff('n',' " & 上午上班时间 & "',Timeserial(Datepart('h',上午刷卡),Datepart('n',上午刷卡),Datepart('s',上午刷卡)))) <=  " & 上午迟到允许 & ","
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                      '正常','迟到')) AS 上午考勤结果,(SELECT TOP 1 t_d_CardRecord.f_ReadDate"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                             FROM   t_d_CardRecord"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                             WHERE  ((t_b_Consumer.f_ConsumerId = t_d_CardRecord.f_ConsumerId"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                      AND (Datediff('d',' " & 考勤开始日期 & "',[t_d_CardRecord].[f_ReadDate])) = 0)"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                     AND ((Datediff('n',' " & 下午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                  Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                  Datepart('s',[t_d_CardRecord].[f_ReadDate])))) >=-  " & 下午刷卡提前 & ""
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                          AND (Datediff('n',' " & 下午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                      Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                      Datepart('s',[t_d_CardRecord].[f_ReadDate])))) <=  " & 下午刷卡延后 & "))) AS 下午刷卡,Iif(Isnull(下午刷卡),'未刷卡',Iif((Datediff('n',' " & 下午上班时间 & "',Timeserial(Datepart('h',下午刷卡),Datepart('n',下午刷卡),Datepart('s',下午刷卡)))) <=  " & 下午迟到允许 & ","
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           '正常','迟到')) AS 下午考勤结果,Iif(上午考勤结果 = '迟到',1 + Iif(下午考勤结果 = '迟到',1,0),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Iif(下午考勤结果 = '迟到',1,0)) AS 迟到次数,Iif(上午考勤结果 = '未刷卡',1 + Iif(下午考勤结果 = '未刷卡',1,0),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         Iif(下午考勤结果 = '未刷卡',1,0)) AS 未刷卡次数,迟到次数 + 未刷卡次数 AS 违纪总数"
strsql1 = strsql1 & " FROM     t_b_Consumer"
strsql1 = strsql1 & "          LEFT JOIN t_b_Group"
strsql1 = strsql1 & "            ON t_b_Consumer.f_GroupId = t_b_Group.f_GroupId"
strsql1 = strsql1 & " WHERE    (((t_b_Consumer.f_AttendEnabled) = 1))"
strsql1 = strsql1 & "          AND t_b_Consumer.f_GroupId = Iif( " & 部门考勤 & " = 0,t_b_Group.f_GroupId, " & 部门考勤 & ")"
If 日期差 > 0 Then
For i = 1 To 日期差 Step 1
现在日期 = 现在日期 + 1

strsql1 = strsql1 & "UNION all (SELECT   t_b_Consumer.f_ConsumerId AS 编号,t_b_Consumer.f_ConsumerName AS 姓名,t_b_Group.f_GroupName AS 部门,Dateserial(Datepart('yyyy','" & 现在日期 & "'),Datepart('m','" & 现在日期 & "'),"
strsql1 = strsql1 & "                                                                                                                   Datepart('d','" & 现在日期 & "')) AS 日期,(SELECT TOP 1 t_d_CardRecord.f_ReadDate"
strsql1 = strsql1 & "                                                                                                                                                        FROM   t_d_CardRecord"
strsql1 = strsql1 & "                                                                                                                                                        WHERE  ((t_b_Consumer.f_ConsumerId = t_d_CardRecord.f_ConsumerId"
strsql1 = strsql1 & "                                                                                                                                                                 AND (Datediff('d','" & 现在日期 & "',[t_d_CardRecord].[f_ReadDate])) = 0)"
strsql1 = strsql1 & "                                                                                                                                                                AND ((Datediff('n',' " & 上午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                             Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                             Datepart('s',[t_d_CardRecord].[f_ReadDate])))) >=-  " & 上午刷卡提前 & ""
strsql1 = strsql1 & "                                                                                                                                                                     AND (Datediff('n',' " & 上午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                 Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                 Datepart('s',[t_d_CardRecord].[f_ReadDate])))) <=  " & 上午刷卡延后 & "))) AS 上午刷卡,Iif(Isnull(上午刷卡),'未刷卡',Iif((Datediff('n',' " & 上午上班时间 & "',Timeserial(Datepart('h',上午刷卡),Datepart('n',上午刷卡),Datepart('s',上午刷卡)))) <=  " & 上午迟到允许 & ","
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                      '正常','迟到')) AS 上午考勤结果,(SELECT TOP 1 t_d_CardRecord.f_ReadDate"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                             FROM   t_d_CardRecord"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                             WHERE  ((t_b_Consumer.f_ConsumerId = t_d_CardRecord.f_ConsumerId"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                      AND (Datediff('d',' " & 现在日期 & "',[t_d_CardRecord].[f_ReadDate])) = 0)"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                     AND ((Datediff('n',' " & 下午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                  Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                  Datepart('s',[t_d_CardRecord].[f_ReadDate])))) >=-  " & 下午刷卡提前 & ""
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                          AND (Datediff('n',' " & 下午上班时间 & "',Timeserial(Datepart('h',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                      Datepart('n',[t_d_CardRecord].[f_ReadDate]),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                      Datepart('s',[t_d_CardRecord].[f_ReadDate])))) <=  " & 下午刷卡延后 & "))) AS 下午刷卡,Iif(Isnull(下午刷卡),'未刷卡',Iif((Datediff('n',' " & 下午上班时间 & "',Timeserial(Datepart('h',下午刷卡),Datepart('n',下午刷卡),Datepart('s',下午刷卡)))) <=  " & 下午迟到允许 & ","
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           '正常','迟到')) AS 下午考勤结果,Iif(上午考勤结果 = '迟到',1 + Iif(下午考勤结果 = '迟到',1,0),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Iif(下午考勤结果 = '迟到',1,0)) AS 迟到次数,Iif(上午考勤结果 = '未刷卡',1 + Iif(下午考勤结果 = '未刷卡',1,0),"
strsql1 = strsql1 & "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         Iif(下午考勤结果 = '未刷卡',1,0)) AS 未刷卡次数,迟到次数 + 未刷卡次数 AS 违纪总数"
strsql1 = strsql1 & " FROM     t_b_Consumer"
strsql1 = strsql1 & "          LEFT JOIN t_b_Group"
strsql1 = strsql1 & "            ON t_b_Consumer.f_GroupId = t_b_Group.f_GroupId"
strsql1 = strsql1 & " WHERE    (((t_b_Consumer.f_AttendEnabled) = 1))"
strsql1 = strsql1 & "          AND t_b_Consumer.f_GroupId = Iif( " & 部门考勤 & " = 0,t_b_Group.f_GroupId, " & 部门考勤 & "))"
搜索更多相关主题的帖子: 数据库 难点 
2008-05-17 22:42
xlin1033xl
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:160
专家分:129
注 册:2007-6-24
收藏
得分:0 
太乱了没法看兄弟,
多建几个临时表,然后多表查询
肯定可以解决问题的

-------------程序*酒*人生
2008-05-18 03:56
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 
strsql1 = "SELECT   t_b_Consumer.f_ConsumerId AS 编号,t_b_Consumer.f_ConsumerName AS 姓名,t_b_Group.f_GroupName AS 部门,Dateserial(Datepart('yyyy','" & 考勤开始日期 & "'),Datepart('m','" & 考勤开始日期 & "'),"
strsql1 = strsql1 & "  Datepart('d','" & 考勤开始日期 & "')) AS 日期,(SELECT TOP 1 t_d_CardRecord.f_ReadDate"
strsql1 = strsql1 & "  FROM   t_d_CardRecord"
strsql1 = strsql1 & "   WHERE  ((t_b_Consumer.f_ConsumerId = t_d_CardRecord.f_ConsumerId"
strsql1 = strsql1 & "    AND (Datediff('d','" & 考勤开始日期 & "',[t_d_CardRecord].[f_ReadDate])) = 0)"
strsql1 = strsql1 & "
2008-05-18 11:41
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 
strsql1 = strsql1 & " FROM     t_b_Consumer"
strsql1 = strsql1 & "          LEFT JOIN t_b_Group"
strsql1 = strsql1 & "            ON t_b_Consumer.f_GroupId = t_b_Group.f_GroupId"
strsql1 = strsql1 & " WHERE    (((t_b_Consumer.f_AttendEnabled) = 1))"
strsql1 = strsql1 & "          AND t_b_Consumer.f_GroupId = Iif( " & 部门考勤 & " = 0,t_b_Group.f_GroupId, " & 部门考勤 & ")"
If 日期差 > 0 Then
For i = 1 To 日期差 Step 1
现在日期 = 现在日期 + 1
2008-05-18 11:42
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 
strsql1 = strsql1 & " FROM     t_b_Consumer"
strsql1 = strsql1 & "          LEFT JOIN t_b_Group"
strsql1 = strsql1 & "            ON t_b_Consumer.f_GroupId = t_b_Group.f_GroupId"
strsql1 = strsql1 & " WHERE    (((t_b_Consumer.f_AttendEnabled) = 1))"
strsql1 = strsql1 & "          AND t_b_Consumer.f_GroupId = Iif( " & 部门考勤 & " = 0,t_b_Group.f_GroupId, " & 部门考勤 & ")"
If 日期差 > 0 Then
For i = 1 To 日期差 Step 1
现在日期 = 现在日期 + 1
2008-05-18 11:52
三断笛
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:31
帖 子:1621
专家分:1617
注 册:2007-5-24
收藏
得分:0 
没道德
这长的东西也发上来
2008-05-18 23:09
快速回复:VB数据库中一个难点,请大家帮忙!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050883 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved