机房收费系统之—组合查询
来源:互联网 发布:iphone蜂窝数据用不了 编辑:程序博客网 时间:2024/04/26 16:38
在敲组合查询的时候,我遇到了很多问题,比如说查询的语法怎么连接啊,怎么让控件中的文本信息也就是说字段名,组合关系对应数据库表中的字段哪?
也就是说我们要让卡号=Cardno,让姓名=StudentName ,这样我们在查询的时候才方便了,反成不能直接给Combox的text里面上英文的吧? 于是就定义个函数,让它实现这个功能,函数如下。
<span style="font-size:18px;">Public Function Field(i As String) As String Select Case i Case "卡号" Field = "cardno" Case "姓名" Field = "studentname" Case "上机日期" ...... End selectEnd Function</span>这样就行了。下面这组合查语法以及代码
<span style="font-size:18px;">Private Sub cmdInqurie_Click() Dim ctrl As Control Dim mrc As ADODB.Recordset Dim txtSQL As String Dim Msgtext As String '检查条件输入 If Trim(cmbfeild1.Text) = "" Or Trim(cmboperator1.Text) = "" Or Trim(txt1.Text) = "" Then MsgBox "请输入完整的查询条件", , "提示" Exit Sub End If Dim i, iCols As Integer '让所有列都居中显示文字 iCols = MSFlexGrid1.Cols For i = 0 To iCols - 1 MSFlexGrid1.ColAlignment(i) = flexAlignCenterCenter Next txtSQL = "select * from line_info where " txtSQL = txtSQL & Trim(Field(cmbfeild1.Text)) & Trim((cmboperator1.Text)) & "'" & Trim(txt1.Text) & "'" If Trim(cmbRelation1.Text <> "") Then '第一个组合关系存在 If Trim(cmbfeild2.Text) = "" Or Trim(cmboperator2.Text = "") Or Trim(txt2.Text = "") Then MsgBox "你已经选择了第一个组合关系,请输入第二行查询条件", , "提示" Exit Sub Else txtSQL = txtSQL & Field(Trim(cmbRelation1.Text)) & " " & Field(cmbfeild2.Text) & cmboperator2.Text & "'" & Trim(txt2.Text) & "'" End If End If If Trim(cmbRelation2.Text <> "") Then '第二个组合关系存在 If Trim(cmbfeild3.Text) = "" Or Trim(cmboperator3.Text) = "" Or Trim(txt3.Text) = "" Then MsgBox "你已经选择了第二个组合关系,请输入第三行查询条件", , "提示" Exit Sub Else txtSQL = txtSQL & Field(cmbRelation2.Text) & " " & Field(cmbfeild3.Text) & cmboperator3.Text & "'" & Trim(txt3.Text) & "'" End If End If Set mrc = ExecuteSQL(txtSQL, Msgtext) If mrc.EOF = True Then '检查信息是否存在,如果不存在给出提示并清空所有文本框 MsgBox "没有查询到结果,可能会你输入的信息不存在,或者信息矛盾" ...清空所有文本框 Exit Sub End If With MSFlexGrid1 .Rows = 1 .TextMatrix(0, 0) = "卡号" .TextMatrix(0, 1) = "姓名" ........ Do While Not mrc.EOF .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = Trim(mrc!cardno) .TextMatrix(.Rows - 1, 1) = mrc!studentname ........ mrc.MoveNext Loop End With mrc.CloseEnd Sub</span>
在这个查询中,如果是查询的是日期,你在文本框中输入一堆不是时间格式的东西,系统就会崩溃,解决方法如下
'保持条件的一致性cmbfeild1 If cmbfeild1.Text = "注册时间" Or cmbfeild1.Text = "注册日期" Then If IsDate(Format(txt1.Text, "yyyy-mm-dd")) = False Then’判断是否是日期 MsgBox "请输入正确的时间类型" txt1.Text = "" txt1.SetFocus Exit Sub End If End If代码一大堆,这里面最终的的思想是怎样突破我们的固有思维,怎样创新,让我们的思想灌输进来。我们要用到以前所学的知识,达到学以致用的效果,其实还有比这些写更简便实用的代码等待我们开发,钻研。
3 0
- 机房收费系统之—组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之 组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- 机房收费系统(1)之组合查询
- 机房收费系统之组合查询
- 机房收费系统 之 组合查询BUG
- 机房收费系统之组合查询
- 【机房收费系统】之组合查询
- Redis : under the hood
- 作为程序员,我们需要具备哪些能力?
- ios:详解UIScrollView(转)
- java输入输出流——文件拷贝
- GDAL综合整理--3:Gdal数据模型
- 机房收费系统之—组合查询
- SPRING DATA - REDIS配置
- 非常漂亮的随鼠标移动动的时钟(只支持IE)
- 我喜欢写博客
- 根据年份、月份取当月的天数
- Spark SQL的理解
- GDAL综合整理--4:GDAL目录结构
- HDU1255_覆盖的面积(扫描线/线段树+离散)
- App and driver 电源管理器注册