ASP记录集字段在第二次使用时为空 [英] ASP recordset fileds are empty at second utilisation

查看:68
本文介绍了ASP记录集字段在第二次使用时为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么这句话

Response.write(rs.Fields.Item("password")&" ; "&rs.Fields.Item("password"))

执行此操作:

myPass ; 

这很奇怪,自从今天早上以来,我一直在寻找解决方案.这让我发疯,因为这样做的结果是:

if rs("password") = rs("password") then

是错误的!

经过其他测试,我发现了另一个发现:

Response.write(rs.Fields.Item("name")&" ; "&rs.Fields.Item("name"))

做:

amdin ; admin

如果我通过他的序号索引更改密码",它会显示相同的内容:

myPass ; 

.

相关代码:

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3" 

if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
    Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
    if Request.Form("login") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
    elseif Request.Form("mdp") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
    elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
        sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
        Set rs = Server.CreateObject("ADODB.Recordset")
        rs.open sql, conn

        if rs.eof then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
        elseif rs("mdp") <> Request.Form("mdp") then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
        elseif Request.Form("mdp") = rs("mdp") then
            Session("util_id") = rs("id")
            Session("util_nom") = rs("nom")
            Session("util_couleur") = rs("couleur")
            Session("util_initiales") = rs("initiales")
            Session("util_droit") = rs("droit")
            Session.Timeout = 660 'On créer une session de 11 heures
            rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"

            if Request.Form("redirect") <> "" then
                rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
            end if
        end if
    end if
end if

解决方案

在页面首次运行时,我实际上遇到过此问题,当记录集的第一个值(值)返回一个值,但是第二个时读取记录集(值),它返回null.或者确切地说,您当前的设置正在发生什么.

这实际上不是一个众所周知的问题,但是仍然有多个支持论坛和问题的答案大致相同.

示例页面1
示例页面2

有一些理论可能导致这种情况,例如,表列数据类型说明符中的数据类型不正确.记录集对象中的故障仅返回一次值,因此必须将其存储在对象中.

因为这是返回Null

的同一变量的第二次调用

例如

'  [Good Read-out] - object empties itself
if rs( "password")_
= rs("password") then
' [Bad Read-out] - object no longer contains values. 

这不是一个笼统的声明,而是一个异常,小故障,这没有充分的理由说明它的最小流行程度超出了机器中的鬼影.

要解决此问题:

仅从 ONE 时间的当前记录中读取变量.这将不允许对象为空,因此您以后可以在代码中比较检查,而不必大惊小怪.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3" 

if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
    Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
    if Request.Form("login") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
    elseif Request.Form("mdp") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
    elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
        sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
        Set rs = Server.CreateObject("ADODB.Recordset")
        rs.open sql, conn



        '------------------------------------------------
        'Place record set values in variables first. 
        Dim rMDP, rID, rNom, rCouleur, rInit, rDroit
        rMDP = rs("mdp")
        rID = rs("id")
        rNom = rs("nom")
        rCouleur = rs("couleur")
        rInit = rs("initiales")
        rDroit = rs("droit")
         '------------------------------------------------



        if rs.eof then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
        elseif rMDP <> Request.Form("mdp") then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
        elseif Request.Form("mdp") = rMDP then
            Session("util_id") = rID
            Session("util_nom") = rNom
            Session("util_couleur") = rCouleur
            Session("util_initiales") = rInit
            Session("util_droit") = rDroit
            Session.Timeout = 660 'On créer une session de 11 heures
            rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"

            if Request.Form("redirect") <> "" then
                rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
            end if
        end if
    end if
end if

Does anyone know why this statement

Response.write(rs.Fields.Item("password")&" ; "&rs.Fields.Item("password"))

Do this :

myPass ; 

It's very strange and I'm looking for a solution since this morning. It's making me crazy because the result of this is that this codntion :

if rs("password") = rs("password") then

is False !

EDIT :

After other test, i have made an other discover :

Response.write(rs.Fields.Item("name")&" ; "&rs.Fields.Item("name"))

do :

amdin ; admin

And if i change "password" by his ordinal index it doing the same displays :

myPass ; 

.

EDIT : the related code :

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3" 

if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
    Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
    if Request.Form("login") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
    elseif Request.Form("mdp") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
    elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
        sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
        Set rs = Server.CreateObject("ADODB.Recordset")
        rs.open sql, conn

        if rs.eof then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
        elseif rs("mdp") <> Request.Form("mdp") then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
        elseif Request.Form("mdp") = rs("mdp") then
            Session("util_id") = rs("id")
            Session("util_nom") = rs("nom")
            Session("util_couleur") = rs("couleur")
            Session("util_initiales") = rs("initiales")
            Session("util_droit") = rs("droit")
            Session.Timeout = 660 'On créer une session de 11 heures
            rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"

            if Request.Form("redirect") <> "" then
                rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
            end if
        end if
    end if
end if

解决方案

I've actually had this issue before, when the page made it's first run, the first value of the recordset(value) returns a value, but upon second reading of recordset(value) it returned null. Or excactly what is happening with your current set up.

This is not actually a very well known issue, but there are still several support forums and questions answer along the same lines.

Example Page 1
Example Page 2

There are acouple theories that could cause this, such as, not having the correct data type in the table column data type specifier. A glitch in the recordset object that only returns the value once, and thus, must be stored in an object instead.

Because it is the second calling of the same variable that is returning Null

E.g.

'  [Good Read-out] - object empties itself
if rs( "password")_
= rs("password") then
' [Bad Read-out] - object no longer contains values. 

This is NOT a blanket statement occurrence, this is an anomaly, a glitch, something that doesn't have a solid reason behind it's minimal prevalence beyond the ghost in the machine.

To fix this:

Only read out the variables from the current record ONE time. This will not allow the object to empty and thus you can compare your checks later on in your code without any fuss.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3" 

if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
    Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
    if Request.Form("login") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
    elseif Request.Form("mdp") = "" then
        rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
    elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
        sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
        Set rs = Server.CreateObject("ADODB.Recordset")
        rs.open sql, conn



        '------------------------------------------------
        'Place record set values in variables first. 
        Dim rMDP, rID, rNom, rCouleur, rInit, rDroit
        rMDP = rs("mdp")
        rID = rs("id")
        rNom = rs("nom")
        rCouleur = rs("couleur")
        rInit = rs("initiales")
        rDroit = rs("droit")
         '------------------------------------------------



        if rs.eof then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
        elseif rMDP <> Request.Form("mdp") then
            rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
        elseif Request.Form("mdp") = rMDP then
            Session("util_id") = rID
            Session("util_nom") = rNom
            Session("util_couleur") = rCouleur
            Session("util_initiales") = rInit
            Session("util_droit") = rDroit
            Session.Timeout = 660 'On créer une session de 11 heures
            rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"

            if Request.Form("redirect") <> "" then
                rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
            end if
        end if
    end if
end if

这篇关于ASP记录集字段在第二次使用时为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆