编程论坛's Archiver

zuiainaitang 发表于 2007-6-13 15:58

关于游标的问题--请大家指点

<P>最近在做课程设计--工资管理信息系统,我建了四张表:员工表employee(员工号emp_id、姓名emp_name、性别sex、部门号dept_id)、部门表dept(部门号dept_id、部门名称dept_name、月基本工资salary、津贴allow)、考勤表kaoqin(员工号emp_id、月份kmonth、加班时间jiaban、<BR>事假天数shija)、月工资表msalary(员工号emp_id、月份mmonth、月工资m_salary)<BR><BR>现在做月工资的生成,月工资=部门基本工资+加班时间*津贴-事假*50<BR><BR>在窗口OPEN时间有如下代码,用来向ddlb_1填充1到12个数字,代表的是月份<BR>string j<BR>int i<BR>for i=1 to 12 step 1<BR>    j=string(i)<BR>    ddlb_1.additem(j)<BR>next<BR><BR>下面是生成按钮CLICKED下的代码<BR><BR>integer i,allow,jiaban,shijia<BR>i=integer(ddlb_1.text)<BR>long salary,extr=0<BR>string emp,dept,j<BR><BR>declare xx cursor for //定义游标 XX,从员工表employee中取出员工号emp_id和部门号dept_id<BR>select emp_id,dept_id<BR>from employee;<BR>open xx;<BR>fetch xx into :emp,:dept;<BR>do while sqlca.sqlcode=0<BR>    if trim(emp)="" then<BR>        continue;<BR>    end if<BR>    <BR>    ddlb_2.additem(dept_id)//ddlb_2是我用来检测有没有取到部门号,结果是取到了,ddlb_2出现所有的部门号<BR><BR>    select salary,allow<BR>    into :salary,:allow<BR>    from dept<BR>    where dept_id=:dept;//从部门表dept表中取出月基本工资salary和津贴allow</P>
<P>  j=string(allow)<BR>  <BR>  ddlb_3.additem(j) //用来检测有没有取到salary和allow,<FONT color=#d52b4d>可结果是前面的全为空(没有数值),只有最后一个有数值,大概问题就出在这里</FONT><BR>   </P>
<P>    select jiaban,shijia<BR>    into :jiaban,:shijia<BR>    from kaoqin<BR>    where emp_id=:emp_id and kmonth=:i;<BR>    <BR>    extr=salary+allow*jiaban+shijia*(-50)<BR>   <BR>    <BR>   insert into msalary<BR>    values(:emp_id,:i,:extr);<BR>    <BR>    extr=0<BR>    fetch xx into :emp,:dept;<BR>loop<BR>close xx;<BR><BR><BR><FONT color=#dd226d>我在一本书上看到这个时候该用游标嵌套,各位高手看看该怎么解决,为什么在游标里面用SELECT语句取不出所有数字,只能取最后一个数字,<BR><BR>我这个程序又该怎么写才好!<BR><BR>请指教!!</FONT></P>

路過 发表于 2007-6-18 08:58

<P>感覺寫的怪怪的,有一點煩鎖。<BR>把上面的next放到最後(close xx;)<BR>試一下看看行不行</P>

sam2080 发表于 2007-6-28 16:51

可以用DEBUG跟踪下<BR>然后判断下<BR>ddlb_3.additem(j)的返回值是否有问题

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.