Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / May 2008



Tip: Looking for answers? Try searching our database.

SQL Server bit field is always false. Am I crazy?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon in Canby Or. - 23 Apr 2008 18:21 GMT
I have a SQL Server 2000 record with a bit field that I've verified with
Enterprise Manager to be = 1 but no matter what I do Classic ASP thinks it's
zero.
"field = <%=rs.fields("myfield")%><br>" results in nothing
"field = <%=cstr(rs.fields("myfield"))%><br>" results in nothing
"field = <%=cint(rs.fields("myfield"))%><br>" results in 0
"field = <%=cbool(rs.fields("myfield"))%><br>" results in false

I've changed value from 0 to 1 several times. I get the record when I add
the "where myfield = 1" to my query condition.

This is driving me crazy. Any clues?
Bob Barrows [MVP] - 23 Apr 2008 18:45 GMT
> I have a SQL Server 2000 record with a bit field that I've verified
> with Enterprise Manager to be = 1 but no matter what I do Classic ASP
[quoted text clipped - 8 lines]
>
> This is driving me crazy. Any clues?

We can only guess. Are you looking at the right record?

How about a repro. Here is my attempt to reproduce your problem. I ran
this script on my sql server:
USE [Test]
GO
CREATE TABLE [dbo].[boolTest](
[boolCol] [bit] NOT NULL CONSTRAINT [DF_boolTest_boolCol]  DEFAULT
((1))
) ON [PRIMARY]
go
INSERT INTO [Test].[dbo].[boolTest]
          ([boolCol])
    VALUES
          (1)

Then I ran this code in a test asp page:
<%
dim cn, rs
set cn=createobject("adodb.connection")
cn.Open "provider=sqloledb;data source=clnsqldev;" & _
"initial catalog=test;user id=vbact;password=tcabv"
set rs=cn.Execute("select * from booltest",,1)
if not rs.eof then
response.Write "rs(0) contains """ & rs(0) & """"
end if
rs.close:cn.Close
%>

This is the result that appeared in the browser:

rs(0) contains "True"

Signature

Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jon in Canby Or. - 23 Apr 2008 21:02 GMT
I hear where you're coming from. I did verify I've got the right record. It
gets stranger...

I dropped debug Response.Write statement throughout the code. I did the
rs.Open on line 72. It was on line 420 that I checked the value of the bit
field. So I stuck a debug statement right after the Open and in several spots
throughout the code. In doing that all of a sudden the bit field started
working correctly. I deleted the debug statements and it stopped working. So
right after the Open I put in this code:
    if rs.Fields("MyField") then
    end if
and now the code all works correctly. Some kind of asp bug?

Cheers,
Jon

> > I have a SQL Server 2000 record with a bit field that I've verified
> > with Enterprise Manager to be = 1 but no matter what I do Classic ASP
[quoted text clipped - 41 lines]
>
> rs(0) contains "True"
Bob Barrows [MVP] - 23 Apr 2008 21:37 GMT
> I hear where you're coming from. I did verify I've got the right
> record. It gets stranger...
[quoted text clipped - 9 lines]
> end if
> and now the code all works correctly. Some kind of asp bug?

This is totally outside of my experience. It resembles the old ODBC bug
with TEXT fields (http://www.aspfaq.com/show.asp?id=2188) where you
needed to make them the last field in the select list in order to read
their value (this bug did not appear in the OLE DB provider). as far as
I know, that bug did not affect bit fields ...

Signature

Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Daniel Crichton - 02 May 2008 13:11 GMT
Bob wrote  on Wed, 23 Apr 2008 16:37:46 -0400:

>> I hear where you're coming from. I did verify I've got the right
>> record. It gets stranger...

>> I dropped debug Response.Write statement throughout the code. I did
>> the rs.Open on line 72. It was on line 420 that I checked the value
[quoted text clipped - 5 lines]
>> if rs.Fields("MyField") then end if and now the code all works
>> correctly. Some kind of asp bug?

> This is totally outside of my experience. It resembles the old ODBC bug
> with TEXT fields (http://www.aspfaq.com/show.asp?id=2188) where you
> needed to make them the last field in the select list in order to read
> their value (this bug did not appear in the OLE DB provider). as far as
> I know, that bug did not affect bit fields ...

It would affect bit fields (and any other types) if they were to the left of
the TEXT column, and you tried reading their value after reading the value
of the TEXT column as at this point all the columns to the left of the TEXT
column would have their values discarded.

Signature

Dan

Bob Barrows [MVP] - 02 May 2008 15:26 GMT
> Bob wrote  on Wed, 23 Apr 2008 16:37:46 -0400:
>
[quoted text clipped - 21 lines]
> reading the value of the TEXT column as at this point all the columns
> to the left of the TEXT column would have their values discarded.

Ahh! Good point!
Signature

Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.