Results 1 to 5 of 5

Thread: Urgent help required - trying to add a checkbox column

  1. #1
    Join Date
    Aug 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Urgent help required - trying to add a checkbox column

    Hi, i need some quick help from who has dealt with this before.

    I am trying to add a column to the db using form input for the column name.

    I can add it as any datatype however i need it to be a Yes/No checkbox column. What is the script required to achieve this?

    heres my code:

    SQLadd="ALTER TABLE Models ADD COLUMN `" &namef& "` BIT"
    conn.Execute(SQLad)

    I read somewhere i have to use BIT but i only get value 0 and not an actual check box.


    Any help would be appreciated, thanks.

    MAK

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    posted by mak2204

    I read somewhere i have to use BIT but i only get value 0 and not an actual check box.
    Thats true in SQL Server.

    posted by mak2204

    SQLadd="ALTER TABLE Models ADD COLUMN `" &namef& "` BIT"
    I think you don't need that single quotes there, namef is enclosed in single quotes.

    posted by mak2204

    conn.Execute(SQLad)
    If you have specified the Driver specification and database this line will definitely work.

  3. #3
    Join Date
    Aug 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for reply,
    It all works, but like i said im trying yo get a checkbox field. I am using Access database and BIT isnt working.

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Actually you have to develop the form that contain the checkbox dynamically from your ASP script like the following

    Code:
    response.write "<form method='get' action=''>"
    if(rs("chk") = 1) Then
    response.write "<input type='checkbox' name='check' value=" &<%rs("chk") &" checked> Some Label" 
    else
    response.write "<input type='checkbox' name='check' value=" &<%rs("chk") &"> Some Label"

    The above one is just an example

    If you look at the value part the assumption is you've retrieved the records into a recordset object rs and accessing the field CHK which contains the value from the BIT field

    rs("chk") = 1 represent that the checkbox was checked.
    rs("chk") = 0 represent that the checkbox was not checked

    You need to place this kind of code inside a loop as it needs to work on multiple records.

  5. #5
    Join Date
    Aug 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your reply codexploiter thats really good i didnt even think about that.

    I still wish there was a way to create a checkbox column through sql statement.

    I will however use this method for now as i am on a deadline.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •