VB 用SQL sever查询语句的问题。
Adodc1.RecordSource="select*from"&biaoming&"where类别='产品'"Adodc1.RefreshSetDataGrid1.D...
Adodc1.RecordSource = "select * from " & biaoming & " where 类别 = '产品'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1.Recordset
DataGrid1.Refresh
请问大神 第一句最后的 ‘产品’ 能不能用变量替换掉? 展开
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1.Recordset
DataGrid1.Refresh
请问大神 第一句最后的 ‘产品’ 能不能用变量替换掉? 展开
2个回答
展开全部
可以,不过语句需要修改
dim class as string
Adodc1.RecordSource = "select * from " & biaoming & " where 类别 =“ & class & "
调试一下吧,应该可以
不能直接替换,原因你应该知道
dim class as string
Adodc1.RecordSource = "select * from " & biaoming & " where 类别 =“ & class & "
调试一下吧,应该可以
不能直接替换,原因你应该知道
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以
如果类别 是一个字符型字段
你的变量是 LEIXING
Adodc1.RecordSource = "select * from " & biaoming & " where 类别 = '” & LEIXING & "'"
如果类别 是一个字符型字段
你的变量是 LEIXING
Adodc1.RecordSource = "select * from " & biaoming & " where 类别 = '” & LEIXING & "'"
追问
追答
假设你的四个 combo分别叫
LB,GY,MC,XH
'----------------------------------------------------------------
dim strWhere as string
if lb="忽略" and GY="忽略" and MC=“忽略" and XH=“忽略" then
strwhere=""
else
if lb"忽略" then strwhere= strwhere & iif(len(strwhere)=0,""," and ") & "类别='" & lb & "'"
if GY"忽略" then strwhere= strwhere & iif(len(strwhere)=0,""," and ") & "供应商='" & GY & "'"
if lMC"忽略" then strwhere= strwhere & iif(len(strwhere)=0,""," and ") & "名称='" & MC & "'"
if XH"忽略" then strwhere= strwhere & iif(len(strwhere)=0,""," and ") & "规格型号='" & XH & "'"
strwhere= " WHERE " & strwhere
end if
Adodc1.RecordSource = "select * from " & biaoming & strwhere
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询