Question

  Asked: Apr 3 2008   3:29 PM GMT
  Asked by: Anupamak15


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


Visual Basic .NET, VB.NET, Radio buttons, SQL, 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

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0



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.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development.

Looking for relevant Development Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Mrdenny  |   Apr 4 2008  9:44PM GMT

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.