Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way of saving radio button value in Database 2

Status
Not open for further replies.

ietprofessional

Programmer
Apr 1, 2004
267
US
Hi Everyone,

I have a form that has multiple radio button (yes and no questions).

My concern is, what is the best way of saving these values? I'm guessing boolean.

I'm wanting to save these values in a database (SQL Server) so that I can retrieve them later on.

Just to explain the project a little more what I plan on doing is creating a datagrid with the account name (one of the fields on the original form). The user will choose an account and they will be lead to the form with the account information and the radio buttons (yes or no questions).

 
I would use a Bit field (either a 1 or 0) in the database - SQL Server has no boolean data type.
Then, just use a sqldatareader to iterate through the results of your query and set the Checked property of each radiobutton as necessary.
 
Using a 1 and and zero also has the benefit that you can simply use a SUM in your SQL to find how many postive responses you got for each question.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
When I want to do some databind with this data how do I convert the bit value to a value a checkbox or radiobutton will understand?
 
Now that I have all the checkboxes and yes/no radiobutton data in my database. how do I get that 0/1 bit data back on the form when I want to view the stored data?

How do I make my checkboxes and radiobuttons read the 0's and 1's?

Thanks!
 
Set a boolean value based on whether it is 1 or 0 and then apply that to the checkbox/radiobutton.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Two ways - either create checkboxlists and radiobuttonlists and call
Code:
  myradlist.DataSource = myDataReader
  myradlist.DataBind()

Or, read the datareader something like the following:
Code:
while dr.read
  if dr.getint32(0) = 1 then
    radiobutton1.checked = true
  else
    radiobutton1.checked = false
  end if
end while

That's very simplified.. you'll need to also look up the name of each control from the database and match it to the appropriate one, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top