select语句碰到了问题

shpyw 2004-09-23 12:10:17
我做一个人事系统,可以用编号,姓名等对数据库进行查询,在用编号进行查询时,select * from students where state=true and numbers= & val(txtnumber.text)是可以的,但是我用姓名查找时,总是不行。select * from students where state=true and names= & txtname.text。我总检查不出错在哪里,你们帮我看一下,如何以文本为条件查找数据啊。
...全文
116 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcc 2004-09-23
  • 打赏
  • 举报
回复
ElseIf optxm.Value = True And txtxm.Text <> "" Then
//调试看看判断条件满足吗?
shpyw 2004-09-23
  • 打赏
  • 举报
回复
还是不行啊,说至少一个参数没有被负值。
If optbh.Value = True And txtbh.Text <> "" Then '按编号查找是可以的。
sqlstr = "select * from laogai where gbjdq=true and gbh=" & txtbh.Text
ElseIf optxm.Value = True And txtxm.Text <> "" Then '按姓名查找不可以。
sqlstr = "select * from laogai where gbjdq=true and gxm='" & txtxm.Text & "'"
end if
tztz520 2004-09-23
  • 打赏
  • 举报
回复
楼上正解.
sakurako 2004-09-23
  • 打赏
  • 举报
回复
sqlstr="select * from students where state=true and names='" & txtname.text & "'"
要把文本用'括起来
lifefree 2004-09-23
  • 打赏
  • 举报
回复
打错字了,是看都不用看
lifefree 2004-09-23
  • 打赏
  • 举报
回复
老兄!字段名错了,看都不用年,和数据库里的不一致!
zhaochengqing 2004-09-23
  • 打赏
  • 举报
回复
看一下是不是字段名的问题,我碰到过这样的问题找了半天是字段名和数据库里面的不一样,也可以字段名加“[]“试一下
sqlstr="select * from students where [state]=true and [names]='" & txtname.text & "'"
不过我是这样写的:
sqlstr="select * from students where [state]=true" and "[names]='" & txtname.text & "'""
楼主你试试看!
libingao 2004-09-23
  • 打赏
  • 举报
回复
以下语句试试:
cSql = "select * from students where state=true and " _
& IIf(Trim(txtnumber.Text) <> "", "numbers= " + Trim(txtnumber.Text), " 0=0 ")
cSql = "select * from students where state=true and " _
& IIf(Trim(txtname.Text) <> "", " names= '" + Trim(txtname.Text) + "'", " 0=0 ")
vbman2003 2004-09-23
  • 打赏
  • 举报
回复

Select * From laogai
Where gbjdq=true And gxm='"& Trim(txtxm.Text) &"'"
脚印 2004-09-23
  • 打赏
  • 举报
回复
检查一下数据表的字段 gbjdq 是 True/False 还是 Yes/No.

或者在SQL语句中不要gbjdq=true ,调试一下能否找到你要找的记录
shpyw 2004-09-23
  • 打赏
  • 举报
回复
可是真正的语句是这样的啊:sqlstr = "select * from laogai where gbjdq=true and gxm='" & txtxm.Text & "'" 这样不是已经加了'号了吗?怎么不行啊,急死了啊。
hantaocn 2004-09-23
  • 打赏
  • 举报
回复
难道电脑有问题。。??
szmickylee 2004-09-23
  • 打赏
  • 举报
回复
如果是这样子:sqlstr="select * from laogai where gbjdq=true and gxm='杨洋'"
就对了

字符串两边都加上 ' 号
cosio 2004-09-23
  • 打赏
  • 举报
回复
跟踪一下就知道了!
shpyw 2004-09-23
  • 打赏
  • 举报
回复
调试了一下是这样的:我查找一个叫杨洋的人
sqlstr="select * from laogai where gbjdq=true and gxm=杨洋"

这个查找语句有问题吗?

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧