这语句我改的对吗

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:21:24
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Adodc1.RecordSource = "select * from SelectCourse where (1=1) "
If Trim(NoEdit.Text) = "" And Trim(NameEdit.Text) = "" Then
MsgBox "请选择你要查询的条件并输入你要查询的内容!", vbOKOnly + vbExclamation, "警告"
Exit Sub
Else
If (NoCheck.Value) And (NoEdit.Text <> "") Then
Adodc1.RecordSource = "select * from Student "
sql = sql & " where Sno = '" & Trim(NoEdit.Text) & " '"

End If
If (NameCheck.Value) And (NameEdit.Text <> "") Then
Adodc1.RecordSource = "select * from Student "
sql = sql & " where Sname like '%" & Trim(NameEdit.Text) & "%'"

End If
End If

If rs.EOF Then
MsgBox "Sorry,无法找到你要想查询的学生的基本信息!"
Else

FrmInfo

可以先定义
SQl="Select * from tb where (1=1)"

if 条件 then
sql=sql & " and col1 ='"& text.text &"'"
endif

if 条件1 then
sql=sql & " and col2 ='"& text1.text &"'"
endif

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.open sql,cn,1,1
if rs.eof=true and rs.bof=true then
FrmInfo_Student.Text1.Text = rs("Sno")
FrmInfo_Student.Text2.Text = rs("Sname")
FrmInfo_Student.Text3.Text = rs("Ssex")
FrmInfo_Student.Text4.Text = rs("Sage")
FrmInfo_Student.Text5.Text = rs("Splace")
FrmInfo_Student.Text6.Text = rs("Spolity")
FrmInfo_Student.Text7.Text = rs("Stime")
FrmInfo_Student.Text8.Text = rs("Steleph")
endif

我看着像看天书!——晕!