View Full Version : Urgent help required - trying to add a checkbox column
mak2204
09-21-2006, 03:06 PM
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
codeexploiter
09-22-2006, 04:54 AM
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.
mak2204
09-22-2006, 08:57 AM
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.
codeexploiter
09-22-2006, 09:13 AM
Actually you have to develop the form that contain the checkbox dynamically from your ASP script like the following
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.
mak2204
09-22-2006, 11:05 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.