vb6.0 在SQL数据库中使用 组合查询的模糊查询:SQL语句
我想试用下面语句做一个条件查询,但不行:Adodc1.RecordSource="select*from客户信息where客户编号=like"&txtSearchGues...
我想试用下面语句做一个条件查询,但不行:
Adodc1.RecordSource = "select * from 客户信息 where 客户编号=like" & txtSearchGuestNo.Text & "%"
Adodc1.Refresh
求救呀:我是想在Text1,Text2,Text3,在command1的点击事件下进行模糊查询,然后在DaraGrid显示。。。。
谁帮帮我呀,能帮我解决问题的,多多分都愿意加!!
sql = "SELECT 客户编号,客户名称,联系地址,联系电话,邮箱,创建日期,备注 FROM 客户信息 where 1=1"
If txtSearchGuestNo.Text <> "" Then sql = sql & " and 客户编号 like '%" & txtSearchGuestNo.Text & "%'" '客户编号
If txtSearchGuestName.Text <> "" Then sql = sql & " and 客户名称 like '%" & txtSearchGuestName.Text & "%'" '客户名称
If txtSearchTel.Text <> "" Then sql = sql & " and 联系电话 like '%" & txtSearchTel.Text & "%'" '电话
Adodc1.RecordSource = sql
Adodc1.Refresh
这是我结合各位的查询条件,已经成功实现,谢谢各位啦。 展开
Adodc1.RecordSource = "select * from 客户信息 where 客户编号=like" & txtSearchGuestNo.Text & "%"
Adodc1.Refresh
求救呀:我是想在Text1,Text2,Text3,在command1的点击事件下进行模糊查询,然后在DaraGrid显示。。。。
谁帮帮我呀,能帮我解决问题的,多多分都愿意加!!
sql = "SELECT 客户编号,客户名称,联系地址,联系电话,邮箱,创建日期,备注 FROM 客户信息 where 1=1"
If txtSearchGuestNo.Text <> "" Then sql = sql & " and 客户编号 like '%" & txtSearchGuestNo.Text & "%'" '客户编号
If txtSearchGuestName.Text <> "" Then sql = sql & " and 客户名称 like '%" & txtSearchGuestName.Text & "%'" '客户名称
If txtSearchTel.Text <> "" Then sql = sql & " and 联系电话 like '%" & txtSearchTel.Text & "%'" '电话
Adodc1.RecordSource = sql
Adodc1.Refresh
这是我结合各位的查询条件,已经成功实现,谢谢各位啦。 展开
3个回答
展开全部
sSql = "SELECT cBranchID as '客户编号',cBranchName as '客户名称',cBranchTel as '电话',cBranchContact as '联系人 ',cBranchCity as '城市',cBranchAddr as '地址',"
sSql = sSql & "quotename(cUserID)+cUserName as '业务员',cBranchState as '状态 ',cBranchNote as '备注' FROM Branch"
sSql = sSql & " left join Employee on cBranchSalesMan=cUserID where 1=1"
If Text1.Text <> "" Then sSql = sSql & " and cBranchID like '%" & Text1.Text & "%'" '客户编号
If Text2.Text <> "" Then sSql = sSql & " and cBranchName like '%" & Text2.Text & "%'" '客户名称
If Text3.Text <> "" Then sSql = sSql & " and cBranchTel like '%" & Text3.Text & "%'" '电话
If Text4.Text <> "" Then sSql = sSql & " and cBranchContact like '%" & Text4.Text & "%'" '联系人
If Text5.Text <> "" Then sSql = sSql & " and cBranchCity like '%" & Text5.Text & "%'" '城市
If Text6.Text <> "" Then sSql = sSql & " and cBranchAddr like '%" & Text6.Text & "%'" '地址
If Text7.Text <> "" Then sSql = sSql & " and cUserName like '%" & Text7.Text & "%' or cUserID like '%" & Text7.Text & "%'" '业务员
If Text8.Text <> "" Then sSql = sSql & " and cBranchState='" & Text8.Text & "'" '状态
If Text9.Text <> "" Then sSql = sSql & " and cBranchNote like '% " & Text9.Text & "%'" '备注
rs.Open sSql, conn, , adCmdTable
sSql = sSql & "quotename(cUserID)+cUserName as '业务员',cBranchState as '状态 ',cBranchNote as '备注' FROM Branch"
sSql = sSql & " left join Employee on cBranchSalesMan=cUserID where 1=1"
If Text1.Text <> "" Then sSql = sSql & " and cBranchID like '%" & Text1.Text & "%'" '客户编号
If Text2.Text <> "" Then sSql = sSql & " and cBranchName like '%" & Text2.Text & "%'" '客户名称
If Text3.Text <> "" Then sSql = sSql & " and cBranchTel like '%" & Text3.Text & "%'" '电话
If Text4.Text <> "" Then sSql = sSql & " and cBranchContact like '%" & Text4.Text & "%'" '联系人
If Text5.Text <> "" Then sSql = sSql & " and cBranchCity like '%" & Text5.Text & "%'" '城市
If Text6.Text <> "" Then sSql = sSql & " and cBranchAddr like '%" & Text6.Text & "%'" '地址
If Text7.Text <> "" Then sSql = sSql & " and cUserName like '%" & Text7.Text & "%' or cUserID like '%" & Text7.Text & "%'" '业务员
If Text8.Text <> "" Then sSql = sSql & " and cBranchState='" & Text8.Text & "'" '状态
If Text9.Text <> "" Then sSql = sSql & " and cBranchNote like '% " & Text9.Text & "%'" '备注
rs.Open sSql, conn, , adCmdTable
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Adodc1.RecordSource = "select * from 客户信息 where 客户编号 like %" & txtSearchGuestNo.Text & "%"
Adodc1.Refresh
把我的代码拷贝过去,里面去掉了=,添加了%
Adodc1.Refresh
把我的代码拷贝过去,里面去掉了=,添加了%
追问
好像还有报错: txtSearchGuestNo.Text 附近有语法错语。
txtSearchGuestNo.Text (客户编号) 在SQL数据库里定义为:varchar(20)
txtSearchGuestName.Text (客户名称) 在SQL数据库里定义为:Text
txtSearchTel (联系电话) 在SQL数据库里定义为:Text
我想用上面的三个text文本档做模糊查询,能不能帮我写个SQL语呀?用在下面语句
Adodc1.RecordSource=sql
Adodc1.Refresh
麻烦了,,,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询