【VB与数据库】机房收费系统--组合查询
来源:互联网 发布:意大利帅哥 知乎 编辑:程序博客网 时间:2024/05/16 16:57
机房遇到的一个困扰了我两天的问题就是组合查询,但是真的当我完整的做出来之后感觉也是很简单的
首先在加载里面,将各个按钮的选项加载好,当然不要将每个按钮的选项都输一遍,我选择的是给控件创建了数组,用了for循环语句添加上的
然后就是第一个问题,选择一个中文的选项怎样让它在链接数据库的时候改为英文
Public Function Field(i As String) As String Select Case i Case "卡号" Field = "cardno" Case "姓名" Field = "studentname" Case "上机日期" Field = "ondate" Case "上机时间" Field = "ontime" Case "下机日期" Field = "offdate" Case "下机时间" Field = "offtime" Case "消费金额" Field = "consume" Case "余额" Field = "cash" Case "备注" Field = "status" End SelectEnd Function
然后是逻辑值的问题,引文文本框较少,所以就一步一步的添加上的
Private Sub ComboRel1_Click(Index As Integer) If ComboRel1(0).Text = "与" Then Rel1 = "and" End If If ComboRel1(0).Text = "或" Then Rel1 = "or" End If If ComboRel1(1).Text = "与" Then Rel2 = "and" End If If ComboRel1(1).Text = "或" Then Rel2 = "or" End IfEnd Sub
再然后就是链接数据库了,如果一句代码太长的话,容易出错,也不容易查找与修改,所以我就先定义了字段,然后再把几个字段组合成了一句完整的话
Dim Select1 As String Dim Select2 As String Dim Select3 As String Select1 = "" & Trim(Field(ComboStr1(0).Text)) & " " & Trim(ComboSymbol1(0).Text) & " '" & Text1.Text & "'" Select2 = "" & Trim(Field(ComboStr1(1).Text)) & " " & Trim(ComboSymbol1(1).Text) & " '" & Text2.Text & "'" Select3 = "" & Trim(Field(ComboStr1(2).Text)) & " " & Trim(ComboSymbol1(2).Text) & " '" & Text3.Text & "'"
然后对逻辑值进行一个判断,来确定与或关系,并且把链接数据库的sql语句表示正确
'如果两个逻辑运算符都空着 If ComboRel1(0).Text = "" And ComboRel1(1).Text = "" Then If ComboStr1(0).Text = "" Or ComboSymbol1(0).Text = "" Or Text1.Text = "" Then MsgBox "请将查询信息输全!", vbOKOnly + vbExclamation, "温馨提示" Exit Sub Else txtSQL = "select * from Line_Info where " & Select1 & "" Set mrc = ExecuteSQL(txtSQL, msgText) End If End If '如果第一个不空,第二个空 If (Not ComboRel1(0).Text = "") And (ComboRel1(1).Text = "") Then If ComboStr1(0).Text = "" Or ComboSymbol1(0).Text = "" Or Text1.Text = "" Or ComboStr1(1).Text = "" Or ComboSymbol1(1).Text = "" Or Text2.Text = "" Then MsgBox "请将查询信息输全!", vbOKOnly + vbExclamation, "温馨提示" Exit Sub Else txtSQL = "select * from Line_Info where " & Trim(Select1) & " " & Rel1 & " " & Trim(Select2) & "" Set mrc = ExecuteSQL(txtSQL, msgText) End If End If '如果两个都不空 If (Not ComboRel1(0).Text = "") And (Not ComboRel1(1).Text = "") Then If ComboStr1(0).Text = "" Or ComboSymbol1(0).Text = "" Or Text1.Text = "" Or ComboStr1(1).Text = "" Or ComboSymbol1(1).Text = "" Or Text2.Text = "" Or ComboStr1(2).Text = "" Or ComboSymbol1(2).Text = "" Or Text3.Text = "" Then MsgBox "请将查询信息输全!", vbOKOnly + vbExclamation, "温馨提示" Exit Sub Else If ComboRel1(0).Text = "或" And ComboRel1(1).Text = "与" Then txtSQL = "select * from Line_Info where (" & Select1 & " " & Rel1 & " " & Select2 & ") " & Rel2 & " " & Select3 & "" Set mrc = ExecuteSQL(txtSQL, msgText) Else If ComboRel1(0).Text = "与" And ComboRel1(1).Text = "或" Then txtSQL = "select * from Line_Info where " & Select1 & " " & Rel1 & " (" & Select2 & " " & Rel2 & " " & Select3 & ")" Set mrc = ExecuteSQL(txtSQL, msgText) Else txtSQL = "select * from Line_Info where " & Select1 & " " & Rel1 & " " & Select2 & " " & Rel2 & " " & Select3 & "" Print txtSQL Set mrc = ExecuteSQL(txtSQL, msgText) End If End If End If End If
总结
我觉得这段代码最重要的就是搞清楚代码的逻辑关系,然后再进行判断与调试。另外代码的重复可以用调用的方法重复使用,这样可以使代码更加简洁明了。
阅读全文
2 0
- 【VB与数据库】机房收费系统--组合查询
- 【VB与数据库】机房收费系统--序
- VB.NET 机房收费系统之组合查询
- VB.NET机房收费系统——组合查询
- 组合查询(vb.net版,机房收费系统)
- 组合查询(vb.net+三层架构之机房收费系统)
- vb.net机房收费系统—组合查询的实现
- VB.NET版机房收费系统之组合查询
- 机房收费系统个人版——VB.NET组合查询
- VB.NET+三层 机房收费系统之组合查询
- VB.NET版机房收费系统---组合查询
- vb.net机房收费系统之组合查询
- 【机房收费系统】VB中的组合查询探索
- VB.NET版机房收费系统之组合查询
- 机房收费系统组合查询
- 机房收费系统---组合查询
- 机房收费系统@组合查询
- 机房收费系统---组合查询
- 简单概率问题(先验,后验)
- Oracle定时执行计划任务
- 如何用递归算法判断一个数组是否是递增
- Qt Creator中常用快捷键
- n皇后
- 【VB与数据库】机房收费系统--组合查询
- LinkedTransferQueue 用法
- 基于 mini2440 电阻式触摸屏(三):Linux输入子系统(InputSubsystem)
- python opencc 卡住
- webview加载https地址图片显示不出来问题
- 对栈桢的初步理解
- 图片指纹技术检测图片相似度
- 利用Jenkins玩转Android自动打包发包
- JVM高级特性与实践(一):Java内存区域 与 内存溢出异常