| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 905 人关注过本帖
标题:关于多表视图数据在grid中修改后,不能更新数据源表中的数据
只看楼主 加入收藏
jsfchqf
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-8-19
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:11 
关于多表视图数据在grid中修改后,不能更新数据源表中的数据
我有kq和jj两个表,想通过建立视图,在grid表中对数据进行录入和修改,但是修改后的数据不能更新到两个原表中,我通过视图设计器进行建立的视图,修改的数据能够更新到原表,不知在编程中如何实现,请哪位老大帮忙.
代码如下:
OPEN DATABASE gzbase
SET SAFETY  Off
  use
  tmp_year=alltrim(str(thisform.spn_year.value))         &&定义查询数据的年份

**2012年1月修改
  filepath="e:\gz\"+tmp_year+"年工资数据"
  SET PATH TO &filepath
**以上行内容

  tmp_month=alltrim(str(thisform.spn_month.value))       &&定义查询数据的月份
   if len(tmp_month)=1                                   &&如果月份小于10月,月份前加零,否则不加零
       fbs_name='bs_'+tmp_year+'0'+tmp_month+'.dbf'
       fkq_name='kq_'+tmp_year+'0'+tmp_month+'.dbf'
       fjj_name='jj_'+tmp_year+'0'+tmp_month+'.dbf'
   else
       fbs_name='bs_'+tmp_year+tmp_month+'.dbf'
       fkq_name='kq_'+tmp_year+tmp_month+'.dbf'
       fjj_name='jj_'+tmp_year+tmp_month+'.dbf'
   ENDIF

    IF  file('&fbs_name')
       USE &fbs_name ALIAS bs IN 2
    else
        MESSAGEBOX("没有数据表,请检查年月....",1,3000)
        RETURN
    ENDIF
   
**    ADD TABLE &fkq_name
**    ADD TABLE &fjj_name
*!*     
*!*    IF SUBSTR(ALLTRIM(thisform.treeview1.selectedItem.Text),1,1)='A'
*!*      cbmdm=" "
*!*      CREATE SQL VIEW kq_view2 as;
*!*         SELECT kq.gh 工号,kq.name 姓名,kq.ycq 应勤,kq.scq 实勤,kq.sjts 事假,kq.bjts 病假,kq.bjlb 类别,kq.kgts 旷工,kq.gsts 工伤,kq.cjts 产假,kq.hjts 婚假,kq.tqjr 探亲假,;
*!*      kq.sjr 丧假,kq.jbgr_sat 周六加班,kq.jbgr_sun 周日加班,kq.jr_jb 节日加班,jj.ccjj 超产奖金,jj.zljp 质量奖赔,jj.gwjt 岗位津贴,jj.qtjt 其它奖金,;
*!*      jj.qtgz 其它工资,jj.flf 福利费,jj.jbgze1 周六加班费,jj.jbgze2 周日加班费,jj.jbgze3 节日加班费,jj.xybs 中班, jj.dybs 夜班,jj.dkk1 补扣保险费,jj.dkk2 代扣款项,jj.dk_cqj 违纪扣款,jj.dkdf 代扣电费,jj.gh 工号1;
*!*    FROM &fkq_name kq ,&fjj_name jj;
*!*    WHERE kq.gh=jj.gh ORDER BY kq.bmdm,kq.gh desc
*!*    else
      cbmdm=SUBSTR(ALLTRIM(thisform.treeview1.selectedItem.Text),1,5)
*!*    CREATE SQL VIEW kq_view2 as;
*!*      SELECT kq.gh 工号,kq.name 姓名,kq.ycq 应勤,kq.scq 实勤,kq.sjts 事假,kq.bjts 病假,kq.bjlb 类别,kq.kgts 旷工,kq.gsts 工伤,kq.cjts 产假,kq.hjts 婚假,kq.tqjr 探亲假,;
*!*      kq.sjr 丧假,kq.jbgr_sat 周六加班,kq.jbgr_sun 周日加班,kq.jr_jb 节日加班,jj.ccjj 超产奖金,jj.zljp 质量奖赔,jj.gwjt 岗位津贴,jj.qtjt 其它奖金,;
*!*      jj.qtgz 其它工资,jj.flf 福利费,jj.jbgze1 周六加班费,jj.jbgze2 周日加班费,jj.jbgze3 节日加班费,jj.xybs 中班,jj.dybs 夜班,jj.dkk1 补扣保险费,jj.dkk2 代扣款项,jj.dk_cqj 违纪扣款,jj.dkdf 代扣电费,jj.gh 工号1;
*!*    FROM &fkq_name kq , &fjj_name jj ;
*!*    WHERE kq.gh=jj.gh AND kq.bmdm=cbmdm ORDER BY kq.bmdm,kq.gh desc

*!*    ENDIF

use kq_view

DBSetProp('kq_view',"View","SendUpdates",.T.)
DBSetProp('kq_view',"View","BatchUpdateCount",1)
DBSetProp('kq_view',"View","CompareMemo",.T.)
DBSetProp('kq_view',"View","FetchAsNeeded",.F.)
DBSetProp('kq_view',"View","FetchMemo",.T.)
DBSetProp('kq_view',"View","FetchSize",100)
DBSetProp('kq_view',"View","MaxRecords",-1)
DBSetProp('kq_view',"View","Prepared",.F.)
DBSetProp('kq_view',"View","UpdateType",1)
DBSetProp('kq_view',"View","UseMemoSize",255)
DBSetProp('kq_view',"View","Tables","kq_201509,jj_201509")
DBSetProp('kq_view',"View","WhereType",3)


DBSetProp("kq_view"+".工号","Field","DataType","C(8)")
DBSetProp("kq_view"+".工号","Field","UpdateName","kq.gh")
DBSetProp("kq_view"+".工号","Field","KeyField",.T.)
DBSetProp("kq_view"+".工号","Field","Updatable",.T.)

DBSetProp("kq_view"+".工号1","Field","DataType","C(8)")
DBSetProp("kq_view"+".工号1","Field","UpdateName","jj.gh")
DBSetProp("kq_view"+".工号1","Field","KeyField",.T.)
DBSetProp("kq_view"+".工号1","Field","Updatable",.T.)

DBSetProp("kq_view"+".姓名","Field","DataType","C(6)")
DBSetProp("kq_view"+".姓名","Field","UpdateName","kq.name")
DBSetProp("kq_view"+".姓名","Field","KeyField",.F.)
DBSetProp("kq_view"+".姓名","Field","Updatable",.T.)

DBSetProp("kq_view"+".应勤","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".应勤","Field","UpdateName","kq.ycq")
DBSetProp("kq_view"+".应勤","Field","KeyField",.F.)
DBSetProp("kq_view"+".应勤","Field","Updatable",.T.)

DBSetProp("kq_view"+".实勤","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".实勤","Field","UpdateName","kq.scq")
DBSetProp("kq_view"+".实勤","Field","KeyField",.F.)
DBSetProp("kq_view"+".实勤","Field","Updatable",.T.)

DBSetProp("kq_view"+".事假","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".事假","Field","UpdateName","kq.sjts")
DBSetProp("kq_view"+".事假","Field","KeyField",.F.)
DBSetProp("kq_view"+".事假","Field","Updatable",.T.)

DBSetProp("kq_view"+".病假","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".病假","Field","UpdateName","kq.bjts")
DBSetProp("kq_view"+".病假","Field","KeyField",.F.)
DBSetProp("kq_view"+".病假","Field","Updatable",.T.)

DBSetProp("kq_view"+".类别","Field","DataType","C(2)")
DBSetProp("kq_view"+".类别","Field","UpdateName","kq.bjlb")
DBSetProp("kq_view"+".类别","Field","KeyField",.F.)
DBSetProp("kq_view"+".类别","Field","Updatable",.T.)

DBSetProp("kq_view"+".旷工","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".旷工","Field","UpdateName","kq.kgts")
DBSetProp("kq_view"+".旷工","Field","KeyField",.F.)
DBSetProp("kq_view"+".旷工","Field","Updatable",.T.)

DBSetProp("kq_view"+".工伤","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".工伤","Field","UpdateName","kq.gsts")
DBSetProp("kq_view"+".工伤","Field","KeyField",.F.)
DBSetProp("kq_view"+".工伤","Field","Updatable",.T.)

DBSetProp("kq_view"+".产假","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".产假","Field","UpdateName","kq.cjts")
DBSetProp("kq_view"+".产假","Field","KeyField",.F.)
DBSetProp("kq_view"+".产假","Field","Updatable",.T.)

DBSetProp("kq_view"+".婚假","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".婚假","Field","UpdateName","kq.hjts")
DBSetProp("kq_view"+".婚假","Field","KeyField",.F.)
DBSetProp("kq_view"+".婚假","Field","Updatable",.T.)

DBSetProp("kq_view"+".探亲假","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".探亲假","Field","UpdateName","kq.tqjr")
DBSetProp("kq_view"+".探亲假","Field","KeyField",.F.)
DBSetProp("kq_view"+".探亲假","Field","Updatable",.T.)

DBSetProp("kq_view"+".丧假","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".丧假","Field","UpdateName","kq.sjr")
DBSetProp("kq_view"+".丧假","Field","KeyField",.F.)
DBSetProp("kq_view"+".丧假","Field","Updatable",.T.)

DBSetProp("kq_view"+".周六加班","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".周六加班","Field","UpdateName","kq.jbgr_sat")
DBSetProp("kq_view"+".周六加班","Field","KeyField",.F.)
DBSetProp("kq_view"+".周六加班","Field","Updatable",.T.)

DBSetProp("kq_view"+".周日加班","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".周日加班","Field","UpdateName","kq.jbgr_sun")
DBSetProp("kq_view"+".周日加班","Field","KeyField",.F.)
DBSetProp("kq_view"+".周日加班","Field","Updatable",.T.)

DBSetProp("kq_view"+".节日加班","Field","DataType","N(4,1)")
DBSetProp("kq_view"+".节日加班","Field","UpdateName","kq.jr_jb")
DBSetProp("kq_view"+".节日加班","Field","KeyField",.F.)
DBSetProp("kq_view"+".节日加班","Field","Updatable",.T.)

DBSetProp("kq_view"+".超产奖金","Field","DataType","N(12,2)")
DBSetProp("kq_view"+".超产奖金","Field","UpdateName","jj_201509.ccjj")
DBSetProp("kq_view"+".超产奖金","Field","KeyField",.F.)
DBSetProp("kq_view"+".超产奖金","Field","Updatable",.T.)

DBSetProp("kq_view"+".质量奖赔","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".质量奖赔","Field","UpdateName","jj_201509.zljp")
DBSetProp("kq_view"+".质量奖赔","Field","KeyField",.F.)
DBSetProp("kq_view"+".质量奖赔","Field","Updatable",.T.)

DBSetProp("kq_view"+".岗位津贴","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".岗位津贴","Field","UpdateName","jj_201509.gwjt")
DBSetProp("kq_view"+".岗位津贴","Field","KeyField",.F.)
DBSetProp("kq_view"+".岗位津贴","Field","Updatable",.T.)

DBSetProp("kq_view"+".其它奖金","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".其它奖金","Field","UpdateName","jj_201509.qtjt")
DBSetProp("kq_view"+".其它奖金","Field","KeyField",.F.)
DBSetProp("kq_view"+".其它奖金","Field","Updatable",.T.)

DBSetProp("kq_view"+".其它工资","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".其它工资","Field","UpdateName","jj_201509.qtgz")
DBSetProp("kq_view"+".其它工资","Field","KeyField",.F.)
DBSetProp("kq_view"+".其它工资","Field","Updatable",.T.)

DBSetProp("kq_view"+".福利费","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".福利费","Field","UpdateName","jj_201509.flf")
DBSetProp("kq_view"+".福利费","Field","KeyField",.F.)
DBSetProp("kq_view"+".福利费","Field","Updatable",.T.)

DBSetProp("kq_view"+".周六加班费","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".周六加班费","Field","UpdateName","jj_201509.jbgze1")
DBSetProp("kq_view"+".周六加班费","Field","KeyField",.F.)
DBSetProp("kq_view"+".周六加班费","Field","Updatable",.T.)

DBSetProp("kq_view"+".周日加班费","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".周日加班费","Field","UpdateName","jj_201509.jbgze2")
DBSetProp("kq_view"+".周日加班费","Field","KeyField",.F.)
DBSetProp("kq_view"+".周日加班费","Field","Updatable",.T.)

DBSetProp("kq_view"+".节日加班费","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".节日加班费","Field","UpdateName","jj_201509.jbgze3")
DBSetProp("kq_view"+".节日加班费","Field","KeyField",.F.)
DBSetProp("kq_view"+".节日加班费","Field","Updatable",.T.)

DBSetProp("kq_view"+".中班","Field","DataType","N(4)")
DBSetProp("kq_view"+".中班","Field","UpdateName","jj_201509.xybs")
DBSetProp("kq_view"+".中班","Field","KeyField",.F.)
DBSetProp("kq_view"+".中班","Field","Updatable",.T.)

DBSetProp("kq_view"+".夜班","Field","DataType","N(4)")
DBSetProp("kq_view"+".夜班","Field","UpdateName","jj_201509.dybs")
DBSetProp("kq_view"+".夜班","Field","KeyField",.F.)
DBSetProp("kq_view"+".夜班","Field","Updatable",.T.)

DBSetProp("kq_view"+".补扣保险费","Field","DataType","N(9,2)")
DBSetProp("kq_view"+".补扣保险费","Field","UpdateName","jj_201509.dkk1")
DBSetProp("kq_view"+".补扣保险费","Field","KeyField",.F.)
DBSetProp("kq_view"+".补扣保险费","Field","Updatable",.T.)

DBSetProp("kq_view"+".代扣款项","Field","DataType","N(9,2)")
DBSetProp("kq_view"+".代扣款项","Field","UpdateName","jj_201509.dkk2")
DBSetProp("kq_view"+".代扣款项","Field","KeyField",.F.)
DBSetProp("kq_view"+".代扣款项","Field","Updatable",.T.)

DBSetProp("kq_view"+".违纪扣款","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".违纪扣款","Field","UpdateName","jj_201509.dk_cqj")
DBSetProp("kq_view"+".违纪扣款","Field","KeyField",.F.)
DBSetProp("kq_view"+".违纪扣款","Field","Updatable",.T.)

DBSetProp("kq_view"+".代扣电费","Field","DataType","N(8,2)")
DBSetProp("kq_view"+".代扣电费","Field","UpdateName","jj_201509.dkdf")
DBSetProp("kq_view"+".代扣电费","Field","KeyField",.F.)
DBSetProp("kq_view"+".代扣电费","Field","Updatable",.T.)


SELECT COUNT(*) FROM kq_view INTO ARRAY nbmrs
**SELECT COUNT(*) FROM tmp_kq WHERE 保险种类 in ("A1","A2","A4","A5") INTO ARRAY cb_rs
**SELECT COUNT(*) FROM tmp_kq WHERE (保险种类="A3") INTO ARRAY notcb_rs
thisform.text1.Value=nbmrs
thisform.grid1.RecordSourceType=1
thisform.grid1.RecordSource="kq_view"
thisform.grid1.ReadOnly= .F.
WITH thisform.grid1
   .column1.width=50
   .column2.width=45
   .column3.width=35
   .column4.width=35
   .column5.width=35
   .column6.width=35
   .column7.width=35
   .column8.width=35
   .column9.width=35
   .column10.width=35
   .column11.width=35
   .column12.width=40
   .column13.width=35
   .column14.width=40
   .column15.width=40
   .column16.width=40
   .column17.width=50
   .column18.width=40
   .column19.width=35
   .column20.width=35
   .column21.width=35
   .column22.width=35
   .column23.width=35
   .column24.width=35
   .column25.width=35
   .column26.width=30
   .column27.width=30
   .column28.width=35
   .column29.width=35
   .column30.width=35
   .column31.width=35
**   .column17.width=80   
endwith
thisform.grid1.Refresh

[ 本帖最后由 jsfchqf 于 2015-9-19 15:35 编辑 ]
搜索更多相关主题的帖子: 如何 数据源 
2015-09-19 15:32
hepingfly
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:195
专家分:657
注 册:2015-5-21
收藏
得分:20 
表单的数据环境里,代码建立可更新视图,再把他作为 grid 的数据源试试。

星际花草
2015-09-19 20:16
jsfchqf
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-8-19
收藏
得分:0 
回复 2楼 hepingfly
能不能讲得具体一点,或者给出操作步骤,我就是不知道具体如何操作。
2015-09-19 21:01
hepingfly
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:195
专家分:657
注 册:2015-5-21
收藏
得分:0 
视图设计器能够实现,说明方法可行。然后,针对这张视图,在视图的修改状态下,查看 ‘显示 SQL’的窗口,将里面的代码拷出来,放入程序中,实现自动生成视图。将此视图作为  grid 的数据源。测试看看结果。

星际花草
2015-09-19 21:27
jsfchqf
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-8-19
收藏
得分:0 
回复 4楼 hepingfly
这个办法我试过了,好像还是不行,上面的代码我就是从视图设计器的SQL中拷过来的。
2015-09-20 04:55
hepingfly
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:195
专家分:657
注 册:2015-5-21
收藏
得分:0 
不行是指的什么不行?考出来的代码生成的视图,先在数据库内,手工测试,看出现什么结果,然后再做做分析。

星际花草
2015-09-21 20:45
jsfchqf
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-8-19
收藏
得分:0 
回复 6楼 hepingfly
我在视图设计器中按步骤设计好视图,然后打开里面的SQL,显示所有代码,并在视图中试着修改数据,完全正确,修改的数据能够更新到源数据表中,但是我将里面的代码全部拷出到命令按钮里,重新运行表单,但修改数据就是不能更新到源数据表中。
2015-09-21 21:11
hepingfly
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:195
专家分:657
注 册:2015-5-21
收藏
得分:0 
没看到楼主的具体实现步骤,也只能猜测。估计还是代码问题,或某个小细节有遗漏吧。如果有那2张原表,并说明要达到的要求,可以让大家一块分析测试测试。

星际花草
2015-09-21 22:43
jsfchqf
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-8-19
收藏
得分:0 
我现在将我的表单发给你以及两张原表发给你,麻烦你帮我看一下如何解决,两个表是动态的,按月生成.
新建文件夹.rar (32.62 KB)
2015-10-10 14:11
jsfchqf
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-8-19
收藏
得分:0 
刚才少了两张表,重新发了一下
新建文件夹.rar (58.56 KB)
2015-10-10 14:14
快速回复:关于多表视图数据在grid中修改后,不能更新数据源表中的数据
数据加载中...
 
   



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

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