博客
关于我
【第一次机房收费系统】—数据库中上下机信息不全问题
阅读量:356 次
发布时间:2019-03-04

本文共 1786 字,大约阅读时间需要 5 分钟。

在做上下机的时候,发现了一个很大的问题,那就是上机信息可以记录,下机的信息没有反应到数据库里面。

在这里插入图片描述
如何解决此问题?
1.想主键。
当你的主键只有卡号的时候,他能不能只通过卡号反应到你数据库中呢?
答案是不能,因为你数据库中下机的信息有很多,同一个卡号可能有多个上下机记录,怎么只能通过卡号来确定你的下机呢。
2.主键+上机时间+上机日期。
利用主键+上机时间+上机日期行不?

txtsqlline = "select * from line_info where cardno='" & txtCardNo.Text & "' and Ondate='" & Trim(txtondate.Text) & "' and ontime='" & Trim(txtontime.Text) & "'"     ' txtSQL = "select * from student_Info Where cardno='" & Trim(txtCardNo.Text) & "'and status='使用'"'and status='正在上机'"    Set mrcLine = ExecuteSQL(txtsqlline, MsgText)

答案:不一定,因为这个要看你的具体代码。

就我而言,这种方法不太好,因为VB执行语句过程中有时间问题,他不可能通过一个时间点把整个语句执行,他只会一条一条的执行。所以一定会有时间延误。
在这里插入图片描述
在这里插入图片描述
看见没,它会有一个2秒的延误。
3.我们把主键换成卡号+状态。
在这里插入图片描述
利用卡号加状态就可以了。

'txtSQL = "select * from Line_Info where status=' 正常上机' and cardno = '" & Trim(txtCID.Text) & "'" '卡号状态是正常上机的,且等于text框的卡号可以下机。    txtsqlline = "select * from Line_Info where status='正在上机' and cardno = '" & Trim(txtCardNo.Text) & "'" '卡号状态是正常上机的,且等于text框的卡号可以下机。   ' txtsqlline = "select * from line_info where cardno='" & txtCardNo.Text & "' and Ondate='" & Trim(txtondate.Text) & "' and ontime='" & Trim(txtontime.Text) & "'"     ' txtSQL = "select * from student_Info Where cardno='" & Trim(txtCardNo.Text) & "'and status='使用'"'and status='正在上机'"    Set mrcLine = ExecuteSQL(txtsqlline, MsgText)'    mrcLine.AddNew    txtclosedate.Text = Format(Date, "yyyy-mm-dd")    txtclosetime.Text = Format(Time, "hh:mm")    mrcLine.Fields(8) = Trim(txtclosedate.Text) 'txtclosedate    mrcLine.Fields(9) = Trim(txtclosetime.Text) 'txtclosetime    mrcLine.Fields(10) = Trim(txtconsumeTime.Text)    mrcLine.Fields(11) = Val(Trim(txtconsumeMoney.Text))    mrcLine.Fields(12) = Val(Trim(txtCardNo.Text))    mrcLine.Fields(13) = "正常下机"    mrcLine.Fields(14) = Trim(VBA.Environ("computername"))    mrcLine.Update    mrcLine.Close

所以,一定要想想主键的问题。

转载地址:http://kxhe.baihongyu.com/

你可能感兴趣的文章
mysql 往字段后面加字符串
查看>>
mysql 快照读 幻读_innodb当前读 与 快照读 and rr级别是否真正避免了幻读
查看>>
MySQL 快速创建千万级测试数据
查看>>
mysql 快速自增假数据, 新增假数据,mysql自增假数据
查看>>
MySql 手动执行主从备份
查看>>
Mysql 批量修改四种方式效率对比(一)
查看>>
Mysql 报错 Field 'id' doesn't have a default value
查看>>
MySQL 报错:Duplicate entry 'xxx' for key 'UNIQ_XXXX'
查看>>
Mysql 拼接多个字段作为查询条件查询方法
查看>>
mysql 排序id_mysql如何按特定id排序
查看>>
Mysql 提示:Communication link failure
查看>>
mysql 插入是否成功_PDO mysql:如何知道插入是否成功
查看>>
Mysql 数据库InnoDB存储引擎中主要组件的刷新清理条件:脏页、RedoLog重做日志、Insert Buffer或ChangeBuffer、Undo Log
查看>>
mysql 数据库中 count(*),count(1),count(列名)区别和效率问题
查看>>
mysql 数据库备份及ibdata1的瘦身
查看>>
MySQL 数据库备份种类以及常用备份工具汇总
查看>>
mysql 数据库存储引擎怎么选择?快来看看性能测试吧
查看>>
MySQL 数据库操作指南:学习如何使用 Python 进行增删改查操作
查看>>
MySQL 数据库的高可用性分析
查看>>
MySQL 数据库设计总结
查看>>