机房--学生基本信息维护思路篇(组合查询)

问题:
1.操作符比较数据库和文本框中数字的大小
2.组合查询

解决方案:
一、把数据库中的需要比较大小的字段的数据类型改为int
例子:就卡号举例子
在数据库中新建查询:

alter table student_Info alter column cardno int not null

代码编写,连接数据库,要查询的数据

txtSQL = "select * from student_Info where cardno < '" & txtContent1.Text & "'"
            Set mrc = ExecuteSQL(txtSQL, Msgtext)

通过以上的代码,再加上判断语句就可以实现此功能

二、解决步骤:
1.首先要理解以下的内容

 txtSQL = "select * from 表名 where 字段名='" & 内容 & "' 

txtsql=之后的内容就是要在数据库中新建查询输入的内容,例如:

 txtSQL = "select * from student_info where cardno='" & 2 & "' 

在数据库中显示的就是

select * from student_info where cardno=' 2 ' 

2.理解了以上内容就能实现2个和3个组合查询

 txtSQL = "select * from student_info where cardno="'" & 2 & "'" & "and(这有一个空格) " & student="'"

3.理清逻辑
①首先看条件是否完整,文本框中的数据根据不同的填入情况而给出相应的提示框
②根据联系建立逻辑关系(可以在纸上简略勾画)
我的简便逻辑:
在这里插入图片描述

这一个代码是实现文本框中是否填写完整和符合第几个条件并根据从c()中的数据,联合查询相应的数据

 	dim c(2) as boolean
 	if 第一条件的文本框只要有一个为空 then
 	else
 		c(0)=true
 		if 第二条件的文本框只要2有一个为空 then
 		else
 		c(1)=true
 			if 第三条件的文本框只要有一个为空 then
 			else
 				c(2)=true
 			end if

下面这一代码是实现组合查询的主体,简单的过程:(组合关系有两个框,上面的为1,下面的为2)

	if c(2) then
		if 组合关系2=“或” then
			组合查询:第一条件 or 第二条件 or 第三条件
		else
				if 组合关系2=“与” then
					组合查询:第一条件 and 第二条件 and 第三条件
				else
					msgbox"请输入第二个组合关系"
				end if
		end if
	else
		if c(1) then
			if 组合关系1=“或” then
				组合查询:第一条件 or 第二条件 
			else
				if 组合关系1=“与” then
					组合查询:第一条件 and 第二条件 
				else
					msgbox"请选择第一个组合关系“	
				end if
			end if
		else
			if c(0) then
				查询:第一条件
			else
				msgbox"请输入第一条件的内容"
			end if
		end if
	end if

				

猜你喜欢

转载自blog.csdn.net/lclcsdnblink/article/details/83691221
今日推荐