开发者

Database result is passed as null unless it's read

开发者 https://www.devze.com 2023-02-17 09:02 出处:网络
Set rslistings = my_conn.Execute(strSQL) Do while NOT rslistings.Eof description = strip(rslistings(\"description\"))
Set rslistings = my_conn.Execute(strSQL)

Do while NOT rslistings.Eof
    description = strip(rslistings("description"))
rslistings.MoveNext
loop

In strip - NULL is being passed. However, if I attach a debugger and inspect the contents of rslistings("description"), then the actual Field object is passed through

It's quite old asp code, but it works on IIS6, just not IIS7

EDIT This only happens on the "description" field with is a text type (MySQL database)

strip doesn't do a lot:

If NOT IsNull(passedinvalue) Then 
    // do something
Else
    // do something else

If I call strip like strip(rs("description")), it is never null as the Field object is passed in. If I assign it to another value, then pa开发者_StackOverflow社区ss it in (like strip(mynewvar)) then the correct value is passed in.

Edit - database bits as requested below

Set my_conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
my_conn.Open "DSN=mydb"

SQL

Set rs = my_conn.Execute("SELECT description FROM table")


the Field Collection is the default member of the Recordset object.

so is the value property for the Field object.

so the following two code statements are equivalent.

Debug.Print objRs.Fields.Item(0)  ' Both statements print 
Debug.Print objRs(0)              '  the Value of Item(0).

it is a difference if you assign a value to a variable or use it as a parameter in a function.


@Paul: If strip doesn't check if description is NULL before working on it, you could do this --

Do while NOT rslistings.Eof
    description = rslistings("description")

    If NOT IsNull(description) Then 
        description = strip(description)
    Else
        description = "" ' or you could have description = " " 
                         ' if you output to screen later on
    End If
rslistings.MoveNext
loop
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号