一個簡單的問題,對數据庫一個表操作時縂出錯(50分)

  • 主题发起人 主题发起人 lcb139
  • 开始时间 开始时间
L

lcb139

Unregistered / Unconfirmed
GUEST, unregistred user!
我先向數據庫中插入數據,代碼如下:<br> &nbsp;FrmMain.DBConnection.BeginTrans;<br> &nbsp;with self.AdoQryTemp do<br> &nbsp;begin<br> &nbsp; &nbsp;close;<br> &nbsp; &nbsp;sql.Text:='INSERT INTO SFIS1.C_EMP_DESC_T (EMP_NO,EMP_NAME,EMP_RANK,CLASS_NAME,STATION_NAME,QUIT_DATE,PASSW)'+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'VALUES(:V0,:V1,:V2,:V3,:V4,:V5,:V6)';<br> &nbsp; &nbsp;parameters[0].Value:=trim(self.edtEmpNo.Text);<br> &nbsp; &nbsp;parameters[1].Value:=trim(self.edtEmpName.Text);<br> &nbsp; &nbsp;parameters[2].Value:=self.cbxRank.Text;<br> &nbsp; &nbsp;parameters[3].Value:=self.CbxClass.Text;<br> &nbsp; &nbsp;parameters[4].Value:=self.CbxStation.Text;<br> &nbsp; &nbsp;parameters[5].Value:=strtodate(FormatdateTime('yyyy/mm/dd',self.DateTimeQUIT.DateTime));<br> &nbsp; &nbsp;parameters[6].Value:='PASSWORD';<br> &nbsp; &nbsp;Try<br> &nbsp; &nbsp; &nbsp;execsql;<br> &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp;FrmMain.DBConnection.RollbackTrans;<br> &nbsp; &nbsp; &nbsp;self.ShowNGMsg('?穝计沮ア毖,叫?穝?刚!');<br> &nbsp; &nbsp; &nbsp;abort;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;FrmMain.DBConnection.CommitTrans;<br> &nbsp;sEMPNO:=trim(self.edtEmpNo.Text);<br> &nbsp;self.btbt_Refresh.Click;<br> &nbsp;self.ADOQryData.Locate('emp_no',sEMPNO,[locaseInsensitive,lopartialkey]);<br> &nbsp;self.ShowPassMsg('穝糤Θ?!');<br>然後再修改這個資料,代碼如下:<br> &nbsp;FrmMain.DBConnection.BeginTrans;<br> &nbsp;with self.AdoQryTemp do<br> &nbsp;begin<br> &nbsp; &nbsp;close;<br> &nbsp; &nbsp;sql.Text:='UPDATE SFIS1.C_EMP_DESC_T SET EMP_NAME=:V0,EMP_RANK=:V1,CLASS_NAME=:V2,STATION_NAME=:V3,'+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'QUIT_DATE=:V4 WHERE EMP_NO=:V5 ';<br> &nbsp; &nbsp;parameters[0].Value:=trim(self.edtEmpName.Text);<br> &nbsp; &nbsp;parameters[1].Value:=self.cbxRank.Text;<br> &nbsp; &nbsp;parameters[2].Value:=self.CbxClass.Text;<br> &nbsp; &nbsp;parameters[3].Value:=self.CbxStation.Text;<br> &nbsp; &nbsp;parameters[4].Value:=strtodate(FormatdateTime('yyyy/mm/dd',self.DateTimeQUIT.DateTime));<br>{開始這句也出這個錯,我改成這樣寫這就不出了,但是下面一句卻出這個錯}<br> &nbsp; &nbsp;parameters[5].Value:=trim(self.edtEmpNo.Text);<br>{錯誤為:應用程式目前的操作所使用的值是個錯誤的類型}<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;execsql;<br> &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp;FrmMain.DBConnection.RollbackTrans;<br> &nbsp; &nbsp; &nbsp;SELF.ShowNGMsg('?穝计沮畐ア毖,叫?穝?刚!');<br> &nbsp; &nbsp; &nbsp;abort;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;FrmMain.DBConnection.CommitTrans;<br> &nbsp;sEMPNO:=trim(self.edtEmpNo.Text);<br> &nbsp;self.btbt_Refresh.Click;<br> &nbsp;self.ADOQryData.Locate('emp_no',sEMPNO,[locaseInsensitive,lopartialkey]);<br> &nbsp;self.ShowPassMsg('?эΘ?!');<br><br>請問是啥原因?應用程式目前的操作所使用的值是個錯誤的類型,沒有錯的阿。<br>trim(self.edtEmpNo.Text);不就是string 的,數據庫是varchar2(25)<br>self.DateTimeQUIT.DateTime出錯,<br>strtodate(FormatdateTime('yyyy/mm/dd',self.DateTimeQUIT.DateTime))爲啥就好了<br>以前我都是像這樣做,這次不知道爲啥出個這樣的錯。<br>對了我先增加再修改才會出錯,我直接修改也不出錯
 
哪個帥哥幫幫忙,是不是表述不清楚啊,表達能力較差,不好意思。
 
首先我认为你这个流程应该改一下!说明了啊,是我认为^呵呵<br> &nbsp;FrmMain.DBConnection.BeginTrans;<br> &nbsp; &nbsp;Try<br> &nbsp;with self.AdoQryTemp do<br> &nbsp;begin<br> &nbsp; &nbsp;close;<br> &nbsp; &nbsp;sql.Text:='INSERT INTO SFIS1.C_EMP_DESC_T (EMP_NO,EMP_NAME,EMP_RANK,CLASS_NAME,STATION_NAME,QUIT_DATE,PASSW)'+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'VALUES(:V0,:V1,:V2,:V3,:V4,:V5,:V6)';<br> &nbsp; &nbsp;parameters[0].Value:=trim(self.edtEmpNo.Text);<br> &nbsp; &nbsp;parameters[1].Value:=trim(self.edtEmpName.Text);<br> &nbsp; &nbsp;parameters[2].Value:=self.cbxRank.Text;<br> &nbsp; &nbsp;parameters[3].Value:=self.CbxClass.Text;<br> &nbsp; &nbsp;parameters[4].Value:=self.CbxStation.Text;<br> &nbsp; &nbsp;parameters[5].Value:=strtodate(FormatdateTime('yyyy/mm/dd',self.DateTimeQUIT.DateTime));<br> &nbsp; &nbsp;parameters[6].Value:='PASSWORD';<br> &nbsp; &nbsp; &nbsp;execsql;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp;FrmMain.DBConnection.RollbackTrans;<br> &nbsp; &nbsp; &nbsp;self.ShowNGMsg('?穝计沮ア毖,叫?穝?刚!');<br> &nbsp; &nbsp; &nbsp;abort;<br> &nbsp;end;
 
还有parameters[4].Value:=strtodate(FormatdateTime('yyyy/mm/dd',self.DateTimeQUIT.DateTime));如果只是想获取年月日,那么可以将DateTimeQUIT组件的TIME属性删除(清空),然后再将DateFormat属性设置为LONG,即可显示为中文格式.
 
self.DateTimeQUIT.DateTime报错我才改为strtodate(FormatdateTime('yyyy/mm/dd',self.DateTimeQUIT.DateTime))的<br>这个都无所谓了<br>我问的是‘應用程式目前的操作所使用的值是個錯誤的類型’错误的原因啦
 
暈,誰幫忙看看啦,我寫這樣就好了,不過看這老別扭<br> &nbsp;FrmMain.DBConnection.BeginTrans;<br> &nbsp;sEMPNO:=trim(self.edtEmpNo.Text);<br> &nbsp;strdate:=FormatdateTime('yyyy/mm/dd',self.DateTimeQUIT.DateTime);<br> &nbsp;with self.AdoQryTemp do<br> &nbsp;begin<br> &nbsp; &nbsp;close;<br> &nbsp; &nbsp;{sql.Text:='UPDATE SFIS1.C_EMP_DESC_T SET EMP_NAME=:V0,EMP_RANK=:V1,CLASS_NAME=:V2,STATION_NAME=:V3,'+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'QUIT_DATE=:V4 WHERE EMP_NO=:V5 '; &nbsp;}<br> &nbsp; &nbsp;sql.Text:='UPDATE SFIS1.C_EMP_DESC_T SET EMP_NAME='''+trim(self.edtEmpName.Text)+''',EMP_RANK='''+self.cbxRank.Text+''',CLASS_NAME='''+self.CbxClass.Text+''',STATION_NAME='''+self.CbxStation.Text+''' '+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;',QUIT_DATE=TO_DATE('''+STRDATE+''',''yyyy/mm/dd'') WHERE EMP_NO='''+sEMPNO+''' ';<br> &nbsp; &nbsp;///parameters[0].Value:=trim(self.edtEmpName.Text);<br> &nbsp; &nbsp;//parameters[1].Value:=self.cbxRank.Text;<br> &nbsp; &nbsp;//parameters[2].Value:=self.CbxClass.Text;<br> &nbsp; &nbsp;//parameters[3].Value:=self.CbxStation.Text;<br> &nbsp; &nbsp;//parameters[4].Value:=self.DateTimeQUIT.DateTime;<br> &nbsp; &nbsp;//parameters[5].Value:=sEMPNO;<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;execsql;<br> &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp;FrmMain.DBConnection.RollbackTrans;<br> &nbsp; &nbsp; &nbsp;SELF.ShowNGMsg('更新數據庫失敗,請重新再試!');<br> &nbsp; &nbsp; &nbsp;abort;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;FrmMain.DBConnection.CommitTrans;<br> &nbsp;self.btbt_Refresh.Click;<br> &nbsp;self.ADOQryData.Locate('emp_no',sEMPNO,[locaseInsensitive,lopartialkey]);<br> &nbsp;self.ShowPassMsg('修改成功!');
 
后退
顶部