Another Checkbox Question

Discussion in 'ASP General' started by The Corinthian, Oct 13, 2004.

  1. I am quite new to ASP scripting and seem to be haveing no success with
    checkboxes at all.

    I have a sql database with bit datatypes and I am trying to create a asp
    webform which will display and update the data from checkboxes.

    Any help would be appreciated.

    Rob
     
    The Corinthian, Oct 13, 2004
    #1
    1. Advertising

  2. What exactly are you having trouble with?

    <input type="checkbox"<% If rs.fields.item(0).value = 1 Then response.write
    " checked"%>>

    Ray at work

    "The Corinthian" <> wrote in message
    news:ckj73c$e2b$...
    >I am quite new to ASP scripting and seem to be haveing no success with
    >checkboxes at all.
    >
    > I have a sql database with bit datatypes and I am trying to create a asp
    > webform which will display and update the data from checkboxes.
    >
    > Any help would be appreciated.
    >
    > Rob
    >
     
    Ray Costanzo [MVP], Oct 13, 2004
    #2
    1. Advertising

  3. The Corinthian

    Rob Guest

    Hi,

    I am probably mssing some thing I am creating my record set using the
    following

    data connection provided by inc file
    <%
    dim rs
    dim strSQL




    set rs=Server.CreateObject ("ADODB.Recordset")
    strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
    WHERE ID ='" & _
    (Session("userid")) & "'"


    Set rs = objConn.Execute (strSQL)



    %>

    using



    <input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
    response.write" checked"%>>



    Returns
    Error Type:
    ADODB.Fields (0x800A0CC1)
    Item cannot be found in the collection corresponding to the requested name
    or ordinal.
    /dbg12/prefs.asp, line 46



    Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:...
    > What exactly are you having trouble with?
    >
    > <input type="checkbox"<% If rs.fields.item(0).value = 1 Then
    > response.write " checked"%>>
    >
    > Ray at work
    >
    > "The Corinthian" <> wrote in message
    > news:ckj73c$e2b$...
    >>I am quite new to ASP scripting and seem to be haveing no success with
    >>checkboxes at all.
    >>
    >> I have a sql database with bit datatypes and I am trying to create a asp
    >> webform which will display and update the data from checkboxes.
    >>
    >> Any help would be appreciated.
    >>
    >> Rob
    >>

    >
    >
     
    Rob, Oct 13, 2004
    #3
  4. You've got it down just fine with just one small part. You forgot to put
    "Arta" in quotes.

    rs.Fields.Item("Arta").Value
    ''or alternatively
    rs.Fields.Item(1).Value
    '''Arta is the second column, so it has an index of 1. Column indexes start
    at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2, Newsletter
    is 3.

    I suggest that you get in the habit of using Option Explicit at the top of
    all your VBS-based ASP pages. If you had Option Explicit, the error would
    have been "Variable is not defined - Arta" or something along those lines.

    Ray at work

    "Rob" <> wrote in message
    news:1Adbd.111$...
    > Hi,
    >
    > I am probably mssing some thing I am creating my record set using the
    > following


    > set rs=Server.CreateObject ("ADODB.Recordset")
    > strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
    > WHERE ID ='" & _
    > (Session("userid")) & "'"
    >
    >
    > <input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
    > response.write" checked"%>>


    > Returns
    > Error Type:
    > ADODB.Fields (0x800A0CC1)
    > Item cannot be found in the collection corresponding to the requested name
    > or ordinal.
    > /dbg12/prefs.asp, line 46
     
    Ray Costanzo [MVP], Oct 13, 2004
    #4
  5. The Corinthian

    Rob Guest

    Ah sorted - thank you very very much


    "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:e49Z$...
    > You've got it down just fine with just one small part. You forgot to put
    > "Arta" in quotes.
    >
    > rs.Fields.Item("Arta").Value
    > ''or alternatively
    > rs.Fields.Item(1).Value
    > '''Arta is the second column, so it has an index of 1. Column indexes
    > start at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2,
    > Newsletter is 3.
    >
    > I suggest that you get in the habit of using Option Explicit at the top of
    > all your VBS-based ASP pages. If you had Option Explicit, the error would
    > have been "Variable is not defined - Arta" or something along those lines.
    >
    > Ray at work
    >
    > "Rob" <> wrote in message
    > news:1Adbd.111$...
    >> Hi,
    >>
    >> I am probably mssing some thing I am creating my record set using the
    >> following

    >
    >> set rs=Server.CreateObject ("ADODB.Recordset")
    >> strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
    >> WHERE ID ='" & _
    >> (Session("userid")) & "'"
    >>
    >>
    >> <input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
    >> response.write" checked"%>>

    >
    >> Returns
    >> Error Type:
    >> ADODB.Fields (0x800A0CC1)
    >> Item cannot be found in the collection corresponding to the requested
    >> name or ordinal.
    >> /dbg12/prefs.asp, line 46

    >
    >
     
    Rob, Oct 13, 2004
    #5
  6. I was a bit hasty there - the returning the values is fine now, but now I am
    trying to update them.

    using

    strSQL = "UPDATE preferences SET"
    strSQL = strSQL & "Arta Request.Form("Arta") & "'"
    strSQL = strSQL & " WHERE ID = Session("UserID")"

    but off course the value "ON" wont go into the bit field, how would I
    convert it so it compatitble.

    Many thanks again.

    Rob
    "Rob" <> wrote in message
    news:yZdbd.1462$...
    > Ah sorted - thank you very very much
    >
    >
    > "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    > message news:e49Z$...
    >> You've got it down just fine with just one small part. You forgot to put
    >> "Arta" in quotes.
    >>
    >> rs.Fields.Item("Arta").Value
    >> ''or alternatively
    >> rs.Fields.Item(1).Value
    >> '''Arta is the second column, so it has an index of 1. Column indexes
    >> start at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2,
    >> Newsletter is 3.
    >>
    >> I suggest that you get in the habit of using Option Explicit at the top
    >> of all your VBS-based ASP pages. If you had Option Explicit, the error
    >> would have been "Variable is not defined - Arta" or something along those
    >> lines.
    >>
    >> Ray at work
    >>
    >> "Rob" <> wrote in message
    >> news:1Adbd.111$...
    >>> Hi,
    >>>
    >>> I am probably mssing some thing I am creating my record set using the
    >>> following

    >>
    >>> set rs=Server.CreateObject ("ADODB.Recordset")
    >>> strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
    >>> WHERE ID ='" & _
    >>> (Session("userid")) & "'"
    >>>
    >>>
    >>> <input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
    >>> response.write" checked"%>>

    >>
    >>> Returns
    >>> Error Type:
    >>> ADODB.Fields (0x800A0CC1)
    >>> Item cannot be found in the collection corresponding to the requested
    >>> name or ordinal.
    >>> /dbg12/prefs.asp, line 46

    >>
    >>

    >
    >
     
    The Corinthian, Oct 14, 2004
    #6
  7. Give the checkbox a value of 1. Also, you have code enclosed in quotes
    below.

    <input name="chkArta" type="checkbox" value="1"<% If
    CBool(rs.Fields.Item(1).Value) Then Response.Write " checked"%>>

    And then in code:

    <%
    Dim iArta
    iArta = Abs(CBool(Request.Form("chkArta")))
    strSQL = "UPDATE preferences SET YourColumnNameHere = " & iArta & " WHERE
    [ID] = " & Session("UserID")
    RESPONSE.WRITE STRSQL
    RESPONSE.END
    %>

    Ray at work



    "The Corinthian" <> wrote in message
    news:ckld7r$g06$...
    >I was a bit hasty there - the returning the values is fine now, but now I
    >am trying to update them.
    >
    > using
    >
    > strSQL = "UPDATE preferences SET"
    > strSQL = strSQL & "Arta Request.Form("Arta") & "'"
    > strSQL = strSQL & " WHERE ID = Session("UserID")"
    >
    > but off course the value "ON" wont go into the bit field, how would I
    > convert it so it compatitble.
     
    Ray Costanzo [MVP], Oct 14, 2004
    #7
  8. The Corinthian

    Rob Guest

    Many thanks yet again, I was nearly there, but didn't set a value nor did I
    know about CBool.

    Cheers again.

    Rob

    "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:%23jAf$...
    > Give the checkbox a value of 1. Also, you have code enclosed in quotes
    > below.
    >
    > <input name="chkArta" type="checkbox" value="1"<% If
    > CBool(rs.Fields.Item(1).Value) Then Response.Write " checked"%>>
    >
    > And then in code:
    >
    > <%
    > Dim iArta
    > iArta = Abs(CBool(Request.Form("chkArta")))
    > strSQL = "UPDATE preferences SET YourColumnNameHere = " & iArta & " WHERE
    > [ID] = " & Session("UserID")
    > RESPONSE.WRITE STRSQL
    > RESPONSE.END
    > %>
    >
    > Ray at work
    >
    >
    >
    > "The Corinthian" <> wrote in message
    > news:ckld7r$g06$...
    >>I was a bit hasty there - the returning the values is fine now, but now I
    >>am trying to update them.
    >>
    >> using
    >>
    >> strSQL = "UPDATE preferences SET"
    >> strSQL = strSQL & "Arta Request.Form("Arta") & "'"
    >> strSQL = strSQL & " WHERE ID = Session("UserID")"
    >>
    >> but off course the value "ON" wont go into the bit field, how would
    >> I convert it so it compatitble.

    >
    >
     
    Rob, Oct 14, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    0
    Views:
    552
    tshad
    Apr 15, 2005
  2. Vikram

    disable checkbox list checkbox

    Vikram, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,414
    ThunderMusic
    Jan 25, 2006
  3. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    844
    David Wier
    Oct 6, 2006
  4. Jason Huang
    Replies:
    0
    Views:
    569
    Jason Huang
    Jun 29, 2007
  5. Terje
    Replies:
    5
    Views:
    392
    Evertjan.
    Nov 18, 2004
Loading...

Share This Page