机房收费系统之查询数据
2016-09-18 19:27
183 查看
前情提示:
作为机房收费系统中非常重要的一个模块,查询数据在困扰我们的学习方面做出了很大的贡献,但我们终究会克服这一困难,使自己得到成长,让自己得到进步。今天就跟大家分享一些我的收获。
我理解的机房收费系统的查询数据主要分为三类:简单查询、时间段内查询、组合查询。
首先是简单查询:
简单查询的思路比较容易理解:就是根据输入的内容来进行查询。需要注意的就是查询的字段与文本框输入的内容相互对应。以查询卡内余额为例,我们应该先去判断卡号是否为空、卡号是否为数字以及查询内容是否存在等相关内容。接下来进行赋值即可。
部分代码如下:
接下来是时间段内的查询:
时间段内的查询思路也比较简单,但是查询语句有点不太好写。首先我们应该判断结束日期是否大于等于开始日期。接下来我们就要写一下查询语句了。我就简单说一下我的,仅供参考。
txtSQL = “select * from ReCharge_Info where date >= ‘” & dtpStart.Value & “’ and date <= ‘” & dtpEnd.Value & “’”
其中dtpStart是开始日期的日期控件,dtpEnd是结束日期的日期控件。这里需要注意的是单引号与双引号的用法,双引号主要是用于vb的程序,而单引号主要是用于数据库的。
具体的单双引号的使用的方法请看我的另一篇博客。
接下来就是赋值语句了,我们需要将从数据库里面查到的数据添加到显示的那个控件里。这里就不做过多的赘述。
最后是组合查询:
组合查询在这几个查询里面算是比较难一点的,但还算比较容易理解。我的思路是这样的:先判断组合条件是否为空,若为空,判断第一行的内容是否完整,若不完整则提示,否则查询,若不为空,判断前两行的查询内容是否完整,不完整则提示,完整则判断第二个组合条件是否为空,若为空则查询,不为空则判断前三行的内容是否完整,不完整则提示,否则三行条件一起查询。代码如下:
总结:查询数据的主要就是理清思路然后写好查询语句,最后将数据添加上就好。当然这仅仅是个人见解,还请大家多提意见。
作为机房收费系统中非常重要的一个模块,查询数据在困扰我们的学习方面做出了很大的贡献,但我们终究会克服这一困难,使自己得到成长,让自己得到进步。今天就跟大家分享一些我的收获。
我理解的机房收费系统的查询数据主要分为三类:简单查询、时间段内查询、组合查询。
首先是简单查询:
简单查询的思路比较容易理解:就是根据输入的内容来进行查询。需要注意的就是查询的字段与文本框输入的内容相互对应。以查询卡内余额为例,我们应该先去判断卡号是否为空、卡号是否为数字以及查询内容是否存在等相关内容。接下来进行赋值即可。
部分代码如下:
txtSQL = "select * from student_Info where" If Not Testtxt(txtCardNO.Text) Then MsgBox "请输入卡号!", vbOKOnly, "提示" txtCardNO.SetFocus Else If Not IsNumeric(txtCardNO.Text) Then MsgBox "卡号请输入数字!", vbOKOnly, "提示" txtCardNO.SetFocus Else txtSQL = "select * from student_Info where cardno ='" & Trim(txtCardNO.Text) & " '" Set mrc = ExecuteSQL(txtSQL, MsgText) If mrc.EOF Then MsgBox "用户不存在,请重新输入!", vbOKOnly, "提示" txtCardNO.Text = "" txtCardNO.SetFocus Else If Trim(mrc.Fields(0)) = Trim(txtCardNO.Text) Then txtStudentNO.Text = Trim(mrc.Fields(1)) txtName.Text = mrc.Fields(2) txtSex.Text = mrc.Fields(3) txtDepartment.Text = mrc.Fields(4) txtGrade.Text = mrc.Fields(5) txtClass.Text = mrc.Fields(6) txtStatus.Text = mrc.Fields(10) txtExplain.Text = mrc.Fields(8) txtBalance.Text = mrc.Fields(7) End If End If End If End If
接下来是时间段内的查询:
时间段内的查询思路也比较简单,但是查询语句有点不太好写。首先我们应该判断结束日期是否大于等于开始日期。接下来我们就要写一下查询语句了。我就简单说一下我的,仅供参考。
txtSQL = “select * from ReCharge_Info where date >= ‘” & dtpStart.Value & “’ and date <= ‘” & dtpEnd.Value & “’”
其中dtpStart是开始日期的日期控件,dtpEnd是结束日期的日期控件。这里需要注意的是单引号与双引号的用法,双引号主要是用于vb的程序,而单引号主要是用于数据库的。
具体的单双引号的使用的方法请看我的另一篇博客。
接下来就是赋值语句了,我们需要将从数据库里面查到的数据添加到显示的那个控件里。这里就不做过多的赘述。
最后是组合查询:
组合查询在这几个查询里面算是比较难一点的,但还算比较容易理解。我的思路是这样的:先判断组合条件是否为空,若为空,判断第一行的内容是否完整,若不完整则提示,否则查询,若不为空,判断前两行的查询内容是否完整,不完整则提示,完整则判断第二个组合条件是否为空,若为空则查询,不为空则判断前三行的内容是否完整,不完整则提示,否则三行条件一起查询。代码如下:
txtSQL = "select * from Line_Info where " If comboRe.Text = "" Then If Not (Testtxt(comboMrc(0).Text) Or Testtxt(comboOp(0).Text) Or txtCon(0).Text = "") Then MsgBox "请输入查询条件!", vbOKOnly, "提示" Exit Sub comboMrc(0).SetFocus Else txtSQL = txtSQL & "" & field(comboMrc(0).Text) & comboOp(0).Text & "'" & txtCon(0).Text & "'" Set mrc = ExecuteSQL(txtSQL, MsgText) GoTo Sentence End If Else If comboRe1.Text = "" Then If comboMrc(1).Text = "" Or comboOp(1).Text = "" Or txtCon(1).Text = "" Then MsgBox "请将第二行选项内容填写完整!", vbOKOnly, "提示" comboMrc(1).SetFocus Exit Sub Else txtSQL = txtSQL & "" & field(comboMrc(0).Text) & comboOp(0).Text & "'" & txtCon(0).Text & "'" txtSQL = txtSQL & " " & field(comboRe.Text) & " " & field(comboMrc(1).Text) & comboOp(1).Text & "'" & txtCon(1).Text & "'" Set mrc = ExecuteSQL(txtSQL, MsgText) GoTo Sentence Exit Sub End If Else If comboMrc(2).Text = "" Or comboOp(2).Text = "" Or txtCon(2).Text = "" Then MsgBox "请将第三行选项内容填写完整!", vbOKOnly, "提示" comboMrc(2).SetFocus Exit Sub Else txtSQL = txtSQL & "" & field(comboMrc(0).Text) & comboOp(0).Text & "'" & txtCon(0).Text & "'" txtSQL = txtSQL & " " & field(comboRe.Text) & " " & field(comboMrc(1).Text) & comboOp(1).Text & "'" & txtCon(1).Text & "'" txtSQL = txtSQL & field(comboRe1.Text) & " " & field(comboMrc(2).Text) & comboOp(2).Text & " '" & txtCon(2).Text & "'" Set mrc = ExecuteSQL(txtSQL, MsgText) GoTo Sentence Exit Sub End If End If End If If mrc.EOF Then MsgBox "该条件的数据不存在,请您重新输入!", vbOKOnly, "提示" comboMrc(0).SetFocus Exit Sub End If Sentence: With myFlexGrid .Rows = 1 .TextMatrix(0, 0) = "卡号" .TextMatrix(0, 1) = "姓名" .TextMatrix(0, 2) = "上机日期" .TextMatrix(0, 3) = "上机时间" .TextMatrix(0, 4) = "下机日期" .TextMatrix(0, 5) = "下机时间" .TextMatrix(0, 6) = "消费金额" .TextMatrix(0, 7) = "余额" .TextMatrix(0, 8) = "备注" .ColWidth(2) = 2000 .ColWidth(4) = 2000 End With If mrc.EOF Then MsgBox "暂无记录,请您重新输入!", vbOKOnly, "提示" Else With myFlexGrid Do While Not mrc.EOF .Rows = .Rows + 1 .CellAlignment = 4 .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1)) .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(3)) .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(6)) .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(7)) .TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(8)) & "" .TextMatrix(.Rows - 1, 5) = Trim(mrc.Fields(9)) & "" .TextMatrix(.Rows - 1, 6) = Trim(mrc.Fields(11)) & "" .TextMatrix(.Rows - 1, 7) = Trim(mrc.Fields(12)) & "" .TextMatrix(.Rows - 1, 8) = Trim(mrc.Fields(13)) & "" mrc.MoveNext Loop mrc.Close End With End If
总结:查询数据的主要就是理清思路然后写好查询语句,最后将数据添加上就好。当然这仅仅是个人见解,还请大家多提意见。
相关文章推荐
- 机房收费系统之—如何查询两个日期之间的数据
- 机房收费系统之—怎样查询两个日期之间的数据
- 机房收费系统问题集(4)——指定时间段数据查询+组合查询
- 机房收费系统之数据查询基础篇
- 机房收费系统高级数据查询之分组查询基础函数部分
- 【机房收费系统】如何查询固定时间段内的数据MSHflexGrid
- 机房收费系统总结(数据连接和查询)
- 机房收费系统之组合查询:基本字符串拼接方法和存储过程实现
- 机房收费系统之组合查询:基本字符串拼接方法和存储过程实现
- 机房收费系统(二)——组合查询
- 机房收费系统---组合查询
- 机房收费系统之上机状态查询
- 机房收费系统之组合查询的发展过程
- VB.Net机房收费系统(三层)——用datagirdview 控件显示数据库数据
- 机房收费系统----组合查询
- vb.net机房收费系统—组合查询的实现
- 机房收费系统--用户级别查询
- VB.NET机房收费系统——组合查询
- 机房收费系统组合查询
- 机房收费系统之组合查询