求助会VB的老鸟帮忙进来看看错误 谢了

想做一个多条件查询并返回影响的结果,但是执行下来却是显示的全部数据库内容实在找不到错误请老鸟给看一下谢了PrivateSub查询_Click(ByValsenderAsS... 想做一个多条件查询 并返回影响的结果,但是执行下来却是显示的全部数据库内容 实在找不到错误 请老鸟给看一下 谢了

Private Sub 查询_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 查询.Click
' Dim registnember As String = Me.查询text.Text.Trim()
Dim engin As New MyDbEngine
Dim reader As DataSet
Dim cmdtext, cx As String
If 学号cb.Checked = True Then
cx = "学号=" & "'学号Text.Text'"
End If

If 院系cb.Checked = True Then
If 学号cb.Checked = False Then
cx = "院系='院系Text.Text '"
Else
cx = cx + " and 院系=' 院系Text.Text '"
End If

End If

If 班级cb.Checked = True Then
If 院系cb.Checked = False And 学号cb.Checked = False Then
cx = "班级='班级Text.Text' "
Else
cx = cx + " and 班级=' 班级Text.Text '"
End If

End If

If 姓名cb.Checked = True Then
If 院系cb.Checked = False And 学号cb.Checked = False And 班级cb.Checked = False Then
cx = "姓名=' '姓名Text.Text '' "
Else
cx = cx + " and 姓名=''姓名Text.Text' ' "
End If
End If

If 专业cb.Checked = True Then

If 院系cb.Checked = False And 学号cb.Checked = False And 班级cb.Checked = False And 姓名cb.Checked = False Then
cx = "专业=' 专业Text.Text' "
Else
cx = cx + " and 专业='专业Text.Text '"
End If
End If

If 性别cb.Checked = True Then

If 院系cb.Checked = False And 学号cb.Checked = False And 班级cb.Checked = False And 姓名cb.Checked = False And 专业cb.Checked = False Then
cx = "性别=' 性别Text.Text '"
Else
cx = cx + " and 性别=' 性别Text.Text '"
End If
End If
If 院系cb.Checked = False And 学号cb.Checked = False And 班级cb.Checked = False And 姓名cb.Checked = False And 专业cb.Checked = False And 性别cb.Checked = False Then
MessageBox.Show("查询内容不能全部为空")
Exit Sub
End If
engin.OpenConnect()
cmdtext = "select * from 表1 where" + "'cx'"
reader = engin.ExecuteDataSet(cmdtext)
engin.CloseConnect()

If reader.Tables.Count > 0 Then
DataGridView1.DataSource = reader.Tables(0)
End If
End Sub
请问1楼的应该怎么改
展开
 我来答
科技程序迷
2010-11-17 · TA获得超过2823个赞
知道大有可为答主
回答量:2240
采纳率:0%
帮助的人:1992万
展开全部
楼主, cmdtext = "select * from 表1 where" + "'cx'"的*用错了吧。
paykka
2025-08-05 广告
由于 Paykka 的所有操作流程都是线上化的,所以推测其支持移动端操作,比如通过 APP 或者适配移动端的网页端。这方便用户随时随地管理自己的账户和资金,提升了使用的便捷性。具体情况可咨询官方确认。... 点击进入详情页
本回答由paykka提供
百度网友5f4ee6b87
2010-11-18 · 超过44用户采纳过TA的回答
知道答主
回答量:82
采纳率:0%
帮助的人:134万
展开全部
哥们,你的组合语句全部都有问题,有问题的地方太多,给你举几个经典的地方吧。其他看着改。
第一句:cx = "学号=" & "'学号Text.Text'"
应该是:cx = "学号='"&学号Text.Text&"'" 这样吧,学号Text.Text应该是录入框吧,你上面那个组合后就变成"学号='学号Text.Text'"这个样子了,等于没把录入的学号引入。
你那种写法相当于将"学号=" 和"'学号Text.Text'"两个字符串合并而不是你原先设想的引入学号Text.Text内容。
下面的错误基本类似,再来看你那个
查询的最后组合语句
cmdtext = "select * from 表1 where" + "'cx'"
这样组合的结果就是"select * from 表1 where 'cx'" 你用的什么数据库?不报错吗?
cmdtext = "select * from 表1 where" + cx
直接这样就好了。你把CX引起来他就是字符串了,跟CX变量可是根本补打
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式