how to store the radio buttons checked value in a database (sql)using vb.net

15 pts.
Tags:
Radio buttons
SQL
VB.NET
Visual Basic .NET
Web development
Iam having 2 radiobuttons in my web form rbown and rbrent for the user to selcet whether he owns a house or he rents.I assigned own and rent as text propertis to the 2 radiobuttons and groupname as group1. Iam trying to store the text values depending on the selection of the radiobuttons in the database with fields own and rent on submit button click event. Inspite of my trials to get the values own and rent in the database,Iam having null valuesin the database. If anybody know how to solve this prob plz help me ASAP regards Anupama you answer is:  //Int32 rd = radioButton1.Checked ? 1 : 0;             //if (rd == 1)             //{             //    radioButton1.Checked = true;             //    radioButton2.Checked = false;             //}             //else             //{             //    radioButton1.Checked = true;             //    radioButton2.Checked = false;             //}
ASKED: April 3, 2008  3:29 PM
UPDATED: August 9, 2012  10:05 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

As you are using radio buttons that means that you only except the user to select one or the other. Proper database design would then dictate that you store the value of the selected radio button in a single field. You should also be storing a numeric value which would then relate to a look up table for proper normalization. Your table should look something like this.

CREATE TABLE YourTable
(Id INT,
OwnershipId INT,
Your Other Columns)

CREATE TABLE Ownership
(OwnershipId INT,
OwnershipDesc NVARCHAR(20))

INSERT INTO Ownership
SELECT 1, ‘Rent’
UNION
SELECT 2, ‘Own’
UNION
SELECT 3, ‘Live With Parents’

Then if they select Rent as the radio button you put 1 into the field. If they select Own you put a 2.

The way you are currently doing it you will always have a NULL in one of the columns.

You should also look into using stored procedures to handle the inserts as this is a much more secure method and will make a lot of this quite a bit easier.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following