[thelist] getting data from 'bit' datatype in asp

James Aylard evolt at pixelwright.com
Wed Jul 10 12:43:01 CDT 2002


> I have some fields stored as "bit" datatypes in SQL Server that I need to
> connect to. What is the right way. For example I write data to the field
> problem with something like:
> objRs.fields("active").value= 1


> Also if I want a form element value to be put in one of these fields, what
> is the right value setting?
> <input type="radio" name="myButton" value="true">
> <input type="radio" name="myButton" value="1">
> <input type="radio" name="myButton" value="???">

    Here's one approach, e.g.:

ASP portion:

Dim strActiveChecked
blnActive = objRs.Fields("Active").Value

If Not IsNull(blnActive) And blnActive Then
   ' The IsNull check is only necessary if your
   ' database is set up to allow nulls for this
   ' field
   strActiveChecked = " checked=""checked"""
   strActiveChecked = ""
End If

HTML portion:

<input type="checkbox" name="Active"<%= strActiveChecked %>>

    Note from my example, though, that you should be using checkboxes, not
radio buttons, if your value is a Boolean. Radio buttons are only
appropriate for selecting between multiple options. Checkboxes are
appropriate for Booleans.

James Aylard

More information about the thelist mailing list