大虾请进(数据老是丢失,但不知什么原因)帮我解决了,要多少分给多少!
开发环境是win2000,中文VB;打包是在英文VB上打包的,打包后的安装环境是win98。
一段数据入库的代码如下,因为入库过程中涉及到修改好几张表,所以使用了事务处理。用户使用过程中说老是会有数据丢失,特别是当跳出一个报告word erroe的对话框以后,刚刚录入的数据会丢失。但在录入过程中是没有问题的,就是重新进入系统后,发现原先录入的数据没了。
On Error GoTo err_proc
conn.BeginTrans '开始事务处理
'---------------------输入检查--------------------
If strSpbm = "" Or strSpmc = "" Or strSpph = "" Or strYxq = "" Or strJhrq = "" Or strJhjg = "" Or strFphm = "" Then
MsgBox "请检查商品编码,名称,批号,有效期,进货日期,单价,发票号码是否输入", vbOKOnly, "警告"
Exit Sub
End If
'进入进货表的同时,进入库存表
'----------------------插入进货信息-------------------------
strMaxIdJh = GetMaxId("SPLSH", "JHXX")
strSqlJh = "insert into JHXX values('" & strMaxIdJh & "','" & strSpbm & "','" & strSpmc & "','" _
& strSpgg & "','" & strSpph & "','" & strYxq & "','" & strJhrq & "'," & strJhjg & "," & strJhbj & "," & strJhsl & ",'" _
& strJldw & "','" & strSccj & "','" & strFphm & "','" & strSpfl & "','" & strCzry & "','" & strBzxx & "','1')"
conn.Execute strSqlJh
'----------------------插入基本信息------------------------
strSql = "select * from SPJBXX where SPBM='" & strSpbm & "'"
DatabaseQuery strSql, rsHave
If rsHave.EOF Then
rsHave.Close
strSqlJbxx = "insert into SPJBXX values('" & strSpbm & "','" & strSpmc & "','" & strSpgg & "')"
conn.Execute strSqlJbxx
Else
rsHave.Close
End If
'---------------------如果生产厂家表中没有该生产厂家,插入该厂家-------------
strSql = "select * from SCCJ where CJMC='" & strSccj & "'"
DatabaseQuery strSql, rsHave
If rsHave.EOF Then
rsHave.Close
strMaxIdSccj = GetMaxId("CJBM", "SCCJ")
strSqlSccj = "insert into SCCJ values('" & strMaxIdSccj & "','" & strSccj & "')"
conn.Execute strSqlSccj
Else
rsHave.Close
End If
'----------------------插入库存信息------------------------
strMaxIdKc = GetMaxId("SPLSH", "KCXX")
strSqlKc = "insert into KCXX values('" & strMaxIdKc & "','" & strSpbm & "','" & strSpmc & "','" _
& strSpgg & "','" & strSpph & "','" & strYxq & "','" & strJhrq & "'," & strJhjg & "," & strJhbj & "," & strJhsl & ",'" _
& strJldw & "','" & strSccj & "','" & strFphm & "','" & strSpfl & "','" & strBzxx & "','0')"
conn.Execute strSqlKc
'-----------------------插入操作日志---------------------------
strSqlRz = "insert into CZRZ values('" & strUser & "','插入入库记录','" & Date & "')"
conn.Execute strSqlRz
conn.CommitTrans '事务提交
dgJhxx.Enabled = True
FillInGrid '查询数据库如果插入了,显示在datagrid中
Exit Sub
err_proc: '出错处理
MsgBox ("数据库操作失败!")
conn.RollbackTrans '事务回滚
Exit Sub
运行了这段代码以后,我会让datagrid去数据库中查询刚刚插入的数据,如果有就显示出来。现在往往插入以后,datagrid中显示该数据已经插入了,但退出系统后,再进去,发现插入的数据又没了,往往伴随着会在退出系统时,弹出一个对话框,报告word error