以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 动态合成查询条件问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=132491) |
-- 作者:gudao123456 -- 发布时间:2019/3/22 21:56:00 -- 动态合成查询条件问题 用SQLFind在后台查询时,查询条件需要加双引号“”,如何才能动态合成带双引号的表达式? Dim dr As DataRow Dim fl As String= "username“ = \'" & username & "\'" & " AndAlso “sfzhm“=\'" & sfzhm & "\'" & " AndAlso password= \'" & password & "\'" dr = DataTables("yhb").SQLFind(fl) fl的外面还应该有个双引号,但如何才能加上去呢?谢谢! |
-- 作者:有点蓝 -- 发布时间:2019/3/22 22:02:00 -- Dim fl As String= "username= \'" & username & "\' And sfzhm=\'" & sfzhm & "\' And password= \'" & password & "\'" |
-- 作者:gudao123456 -- 发布时间:2019/3/22 22:24:00 -- 但这样设查询条件后,结果还是没有查询处理来 执行dr = DataTables("yhb").SQLFind(fl) 后提示错误:“未将对象引用设置到对象的实例。”估计是没查到 是否是查询条件没加没有双引号?因为帮助文档中SQLFind介绍:dr = .SQLFind("产品 =
\'PD01\'","日期") ,这里的查询条件是用双引号“引起来的,谢谢!
|
-- 作者:有点蓝 -- 发布时间:2019/3/22 22:32:00 -- 完整代码贴出来。或者上传实例说明 |
-- 作者:gudao123456 -- 发布时间:2019/3/22 23:14:00 -- Dim wb As New weui \'身份验证 Dim Verified As Boolean \'用于标记用户是否通过了身份验证 Dim UserName As String = e.Cookies("username") \'从cookie中获取用户名 Dim sfzhm As String=e.cookies("sfzhm") \'从cookie中获取身份证号码 Dim Password As String = e.Cookies("password") \'从cookie中获取用户密码 If e.Path = "logon.htm" \'如果是通过登录页面访问,从PostValues即可中提取用户名和密码 If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") \'AndAlso e.PostValues.containsKey("sfzhm") Then username= e.PostValues("username") sfzhm=e.PostValues("sfzhm") Password =EncryptText(e.PostValues("password"),"a23","op#") \' End If End If Dim dr As DataRow Dim fl As String= "username= \'" & username & "\' And sfzhm=\'" & sfzhm & "\' And password= \'" & password & "\' dr = DataTables("yhb").SQLFind(fl) \'从数据库查找户名、身份证号码和密码都相同的记录 If dr IsNot Nothing Then Verified = True End If If Verified AndAlso e.Path = "logon.htm" Then \'如果用户访问的是登录页,且身份验证成功 wb.AppendCookie("username",UserName) \'将用户名和密码写入cookie wb.AppendCookie("sfzhm",sfzhm) wb.AppendCookie("password",Password) wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页 e.WriteString(wb.Build) \'生成网页 Return \'必须的 ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面 wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面 e.WriteString(wb.Build) \'生成网页 Return \'必须的 End If \'开始生成网页 Select Case e.path Case "logon.htm" \'登录页面 wb.AddPageTitle("","pageheader","补助网上申报系统","由月球电子有限公司开发") If e.PostValues.ContainsKey("sfzhm") AndAlso e.PostValues.ContainsKey("password") Then \'判断是否是验证失败后的重新登录 wb.AddTopTips("","toptip1","身份证号码或密码错误!").msec = 2000 \'如果用户通过登录按钮访问,则给用户一个2秒的提示. End If wb.AddForm("","form1","logon.htm") With wb.AddInputGroup("form1","ipg1") .AddInput("username","用户名","text") .AddInput("sfzhm","身份号码","text") .AddInput("password","密码","password") End With With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "登录", "submit") End With Case "exit.htm" \'退出登录 wb.DeleteCookie("username") \'清除cookie中原来的用户名和密码 wb.DeleteCookie("password") wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面 Case "", "default.htm" \'首页 wb.AddPageTitle("","pageheader","补助网上申报系统","由月球电子公司开发") With wb.AddGrid("","g1") .Add("c1","资助申请", "./images/button.png").Attribute = "" .Add("c2","申请审核", "./images/cell.png", "http://www.foxtable.com") .Add("c3","销售统计", "./images/toast.png", "http://www.foxtable.com") .Add("c4","Dialog", "./images/dialog.png", "http://www.foxtable.com") .Add("c5","Progress", "./images/progress.png", "http://www.foxtable.com") .Add("c6","Msg", "./images/msg.png", "http://www.foxtable.com") .Add("c7","Article", "./images/article.png", "http://www.foxtable.com") .Add("c8","ActionSheet", "./images/actionSheet.png", "http://www.foxtable.com") .Add("c9","Icons", "./images/icons.png", "http://www.foxtable.com") .Add("c10","Panel", "./images/panel.png", "http://www.foxtable.com") .Add("c11","Tab", "./images/tab.png", "http://www.foxtable.com") .Add("c12","退出", "./images/exit.png", "exit.htm") \'退出登录 End With End Select e.WriteString(wb.Build) \'生成网页 据我的测试,查询条件是必须用双引号“” 引起来,关键是:动态成出来,如何才能把最外层的双引号能合成进来。
[此贴子已经被作者于2019/3/22 23:34:21编辑过]
|
-- 作者:有点蓝 -- 发布时间:2019/3/23 9:03:00 -- Dim fl As String= "username= \'" & username & "\' And sfzhm=\'" & sfzhm & "\' And password= \'" & password & "\'" msgbox(fl) ‘这里弹出的就是真正的查询表达式 dr = DataTables("yhb").SQLFind(fl) 数据库的列是username、sfzhm、password吗,如果是这个代码肯定没有问题。
|
-- 作者:gudao123456 -- 发布时间:2019/3/23 17:06:00 -- 数据库的列是username、sfzhm、password,没错,但就是不行,后来我改成以下的,就可以了 dr = DataTables("yhb").SQLFind("[username] = \'" & username & "\' And [sfzhm] = \'" & sfzhm & "\'")
|
-- 作者:有点蓝 -- 发布时间:2019/3/23 17:26:00 -- 那就是输入的密码不正确。如果数据库密码是加密的,也要加密后再查询 |
-- 作者:gudao123456 -- 发布时间:2019/3/30 22:55:00 -- 找出问题所在了 [此贴子已经被作者于2019/3/31 0:43:30编辑过]
|