CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeCharge.Discussion

 SQL Server / ASP / bit-fields / checkboxes issue

Print topic Send  topic

Author Message
Seth Wagoner
Posted: 03/06/2001, 7:00 PM

My first post, so I will say the obligatory "Codecharge rocks!", but I have
had a few niggles here and there where it took me a wee while to puzzle
something out - this newsgroup has been very handy in some cases.

However, I've run into one I can't solve easily. An irritating issue other
people may well have noticed (if I'm real lucky maybe it's fixed in
tomorrows release).

Checkboxes fail to function if you're using ASP and a "bit" datatype in SQL
Server 7 (and possibly other versions). The reason is that while you can
_write_ 0 or 1, when it reads that value out of an ASP recordset, it comes
out as "True" or "False". OTOH you can't _write_ "True" or "False" to that
bit field. So you can have input or output, but not both, as it stands.

So since the input and output strings for checkbox fields in CC are the
same, there is no easy solution - so far as I can tell it requires modifying
the ASP code manually at this stage. Irritating when you've got a lot of bit
fields. I _could_ go and change them all to tinyints or something, but that
might cause problems later on down the track.

Not sure what the best fix is for this. But ASP/SQL Server 7 is a fairly
common combo so it may well be worth coming up with one. An ASP guru I know
suggested altering the select string to multiply the bit field by 1 so that
ASP will get a number rather than a bit, like this:

sSQL = "select Website_ID, WebSite_Name, WebSite_URL, WebSite_Quality,
WebSite_Person, WebSite_Company, WebSite_IsCompetitor*1 as
WebSite_IsCompetitor, WebSite_IsAffiliate*1 as WebSite_IsAffiliate,
WebSite_IsComplementary*1 as WebSite_IsComplementary, WebSite_GUID from
WebSite where " & sWhere

and indeed this works, but it can't be applied to a non-numeric field, so
there would have to be some conditional logic in there.

Another alternative is to set different input and output values on the
checkbox, but that would be useless and confusing in most cases.

Seth.

------------------------------------------------------
Seth Wagoner, Webfoundry Ltd
seth@webfoundry.co.nz - http://webfoundry.co.nz


CodeCharge
Posted: 03/06/2001, 9:49 PM

Hi Seth,

I just searched through our past support cases and I see a related issue
where we recommended adding a Show Event:
if fldactive then
fldactive=1
else
fldactive=0
end if
(where "active" is a sample field name)
The issue I'm referring to was due to a problem with ADO converting the bit
value to True/False.
If this is not the right solution, please let us know and we will analyze
your problem closer.

Adam

"Seth Wagoner" <seth@webfoundry.co.nz> wrote in message
> My first post, so I will say the obligatory "Codecharge rocks!", but I
have
> had a few niggles here and there where it took me a wee while to puzzle
> something out - this newsgroup has been very handy in some cases.
>
> However, I've run into one I can't solve easily. An irritating issue other
> people may well have noticed (if I'm real lucky maybe it's fixed in
> tomorrows release).
>
> Checkboxes fail to function if you're using ASP and a "bit" datatype in
SQL
> Server 7 (and possibly other versions). The reason is that while you can
> _write_ 0 or 1, when it reads that value out of an ASP recordset, it comes
> out as "True" or "False". OTOH you can't _write_ "True" or "False" to that
> bit field. So you can have input or output, but not both, as it stands.
>
> So since the input and output strings for checkbox fields in CC are the
> same, there is no easy solution - so far as I can tell it requires
modifying
> the ASP code manually at this stage. Irritating when you've got a lot of
bit
> fields. I _could_ go and change them all to tinyints or something, but
that
> might cause problems later on down the track.
>
> Not sure what the best fix is for this. But ASP/SQL Server 7 is a fairly
> common combo so it may well be worth coming up with one. An ASP guru I
know
> suggested altering the select string to multiply the bit field by 1 so
that
> ASP will get a number rather than a bit, like this:
>
> sSQL = "select Website_ID, WebSite_Name, WebSite_URL, WebSite_Quality,
> WebSite_Person, WebSite_Company, WebSite_IsCompetitor*1 as
> WebSite_IsCompetitor, WebSite_IsAffiliate*1 as WebSite_IsAffiliate,
> WebSite_IsComplementary*1 as WebSite_IsComplementary, WebSite_GUID from
> WebSite where " & sWhere
>
> and indeed this works, but it can't be applied to a non-numeric field, so
> there would have to be some conditional logic in there.
>
> Another alternative is to set different input and output values on the
> checkbox, but that would be useless and confusing in most cases.
>
> Seth.
>
> ------------------------------------------------------
> Seth Wagoner, Webfoundry Ltd
>seth@webfoundry.co.nz - http://webfoundry.co.nz
>
>
>

Laurence Nixon
Posted: 03/07/2001, 7:43 AM

I actually remember seeing this problem longo ago in SQL server 6.5 (I think)
anyway, an interim or long haul solution may be to write an extra bit of code
that converts the True or False to 0 or 1. Your ASP script would first collect
the variables from the the html form :ie

User Name
Is User Active Yes[ ] No[ ]


"database connection"

Dim user, activeuser, varhold
user=Request.Form("user")
activeuser=Request.Form("activeuser")

if activeuser = "True" then
varhold="1"
if activeuser = "False" then
varhold="0"
end if

rst.AddNew
rst("user") = user
rst("activeuser") = varhold


While this is just dummy code I hope I have explained the idea in a way that you
can
work something out provided there is no actual solution.

Laurence Nixon
P.S. Come on guys how about a student rated version of code charge (Pleeaaaase)

Seth Wagoner wrote:

> My first post, so I will say the obligatory "Codecharge rocks!", but I have
> had a few niggles here and there where it took me a wee while to puzzle
> something out - this newsgroup has been very handy in some cases.
>
> However, I've run into one I can't solve easily. An irritating issue other
> people may well have noticed (if I'm real lucky maybe it's fixed in
> tomorrows release).
>
> Checkboxes fail to function if you're using ASP and a "bit" datatype in SQL
> Server 7 (and possibly other versions). The reason is that while you can
> _write_ 0 or 1, when it reads that value out of an ASP recordset, it comes
> out as "True" or "False". OTOH you can't _write_ "True" or "False" to that
> bit field. So you can have input or output, but not both, as it stands.
>
> So since the input and output strings for checkbox fields in CC are the
> same, there is no easy solution - so far as I can tell it requires modifying
> the ASP code manually at this stage. Irritating when you've got a lot of bit
> fields. I _could_ go and change them all to tinyints or something, but that
> might cause problems later on down the track.
>
> Not sure what the best fix is for this. But ASP/SQL Server 7 is a fairly
> common combo so it may well be worth coming up with one. An ASP guru I know
> suggested altering the select string to multiply the bit field by 1 so that
> ASP will get a number rather than a bit, like this:
>
> sSQL = "select Website_ID, WebSite_Name, WebSite_URL, WebSite_Quality,
> WebSite_Person, WebSite_Company, WebSite_IsCompetitor*1 as
> WebSite_IsCompetitor, WebSite_IsAffiliate*1 as WebSite_IsAffiliate,
> WebSite_IsComplementary*1 as WebSite_IsComplementary, WebSite_GUID from
> WebSite where " & sWhere
>
> and indeed this works, but it can't be applied to a non-numeric field, so
> there would have to be some conditional logic in there.
>
> Another alternative is to set different input and output values on the
> checkbox, but that would be useless and confusing in most cases.
>
> Seth.
>
> ------------------------------------------------------
> Seth Wagoner, Webfoundry Ltd
>seth@webfoundry.co.nz - http://webfoundry.co.nz
Seth Wagoner
Posted: 03/07/2001, 9:38 AM

Thanks Laurence and Adam,

Adam's bit of code (modified to my variables) in the Show event worked a
charm.
Might be worth automating it in future to avoid other people's confusion and
support requests.

Seth.


Laurence Nixon
Posted: 03/07/2001, 12:37 PM

Duhh, Next time ill try reading the responses more carefully. It seems Adam had
already written the code for what I was trying to explain and in a much more
elegant manner :-)

Seth Wagoner wrote:

> Thanks Laurence and Adam,
>
> Adam's bit of code (modified to my variables) in the Show event worked a
> charm.
> Might be worth automating it in future to avoid other people's confusion and
> support requests.
>
> Seth.
Anton
Posted: 03/20/2001, 12:33 AM

For example ....
Change this function and change type checkbox on tab Common to "Date".

function getCheckBoxValue(sVal, CheckedValue, UnCheckedValue, sType)
if isempty(sVal) then
if UnCheckedValue = "" then
getCheckBoxValue = "Null"
else
if sType = "Number" then
getCheckBoxValue = UnCheckedValue
else
getCheckBoxValue = "'" & Replace(UnCheckedValue, "'", "''") & "'"
end if
if sType = "Date" then
getCheckBoxValue = 0
end if
end if
else
if CheckedValue = "" then
getCheckBoxValue = "Null"
else
if sType = "Number" then
getCheckBoxValue = CheckedValue
else
getCheckBoxValue = "'" & Replace(CheckedValue, "'", "''") & "'"
end if
if sType = "Date" then
getCheckBoxValue = 1
end if

end if
end if
end function


Laurence Nixon <lnixon@ldnconsulting.com> сообщил в новостях
следующее:3AA65773.B8B4D2ED@ldnconsulting.com...
> I actually remember seeing this problem longo ago in SQL server 6.5 (I
think)
> anyway, an interim or long haul solution may be to write an extra bit of
code
> that converts the True or False to 0 or 1. Your ASP script would first
collect
> the variables from the the html form :ie
>
> User Name
> Is User Active Yes[ ] No[ ]
>
>
> "database connection"
>
> Dim user, activeuser, varhold
> user=Request.Form("user")
> activeuser=Request.Form("activeuser")
>
> if activeuser = "True" then
> varhold="1"
> if activeuser = "False" then
> varhold="0"
> end if
>
> rst.AddNew
> rst("user") = user
> rst("activeuser") = varhold
>
>
> While this is just dummy code I hope I have explained the idea in a way
that you
> can
> work something out provided there is no actual solution.
>
> Laurence Nixon
> P.S. Come on guys how about a student rated version of code charge
(Pleeaaaase)
>
> Seth Wagoner wrote:
>
> > My first post, so I will say the obligatory "Codecharge rocks!", but I
have
> > had a few niggles here and there where it took me a wee while to puzzle
> > something out - this newsgroup has been very handy in some cases.
> >
> > However, I've run into one I can't solve easily. An irritating issue
other
> > people may well have noticed (if I'm real lucky maybe it's fixed in
> > tomorrows release).
> >
> > Checkboxes fail to function if you're using ASP and a "bit" datatype in
SQL
> > Server 7 (and possibly other versions). The reason is that while you can
> > _write_ 0 or 1, when it reads that value out of an ASP recordset, it
comes
> > out as "True" or "False". OTOH you can't _write_ "True" or "False" to
that
> > bit field. So you can have input or output, but not both, as it stands.
> >
> > So since the input and output strings for checkbox fields in CC are the
> > same, there is no easy solution - so far as I can tell it requires
modifying
> > the ASP code manually at this stage. Irritating when you've got a lot of
bit
> > fields. I _could_ go and change them all to tinyints or something, but
that
> > might cause problems later on down the track.
> >
> > Not sure what the best fix is for this. But ASP/SQL Server 7 is a fairly
> > common combo so it may well be worth coming up with one. An ASP guru I
know
> > suggested altering the select string to multiply the bit field by 1 so
that
> > ASP will get a number rather than a bit, like this:
> >
> > sSQL = "select Website_ID, WebSite_Name, WebSite_URL, WebSite_Quality,
> > WebSite_Person, WebSite_Company, WebSite_IsCompetitor*1 as
> > WebSite_IsCompetitor, WebSite_IsAffiliate*1 as WebSite_IsAffiliate,
> > WebSite_IsComplementary*1 as WebSite_IsComplementary, WebSite_GUID from
> > WebSite where " & sWhere
> >
> > and indeed this works, but it can't be applied to a non-numeric field,
so
> > there would have to be some conditional logic in there.
> >
> > Another alternative is to set different input and output values on the
> > checkbox, but that would be useless and confusing in most cases.
> >
> > Seth.
> >
> > ------------------------------------------------------
> > Seth Wagoner, Webfoundry Ltd
> >seth@webfoundry.co.nz - http://webfoundry.co.nz
>


   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.