Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am using one Radiabutton ,Two DropDownBox,I want to store All values in Single Field in sql .please help..,

What I have tried:

i have no idea,please please help me
Posted
Updated 24-May-16 2:43am
Comments
Karthik_Mahalingam 24-May-16 8:11am    
why do you want to store like that?
if so, the data will become messy in the table.
ArjunSingh_as 24-May-16 8:22am    
Reply with some code how you are doing????
jgakenhe 24-May-16 8:29am    
A multivalued attribute is not a good idea. It removes normalization that will lead to data anamolies that will make your data redundant and junky.

My suggestion would be to either create a column for each the .Net controls in your table (easist) or create a new table with those columns where the primary key calls your main table as its foreign key.

Use a varchar field and come up with a format for your data such as "radiovalue|dropdown1value|dropdown2value" and store that in the field as normal. When you read the field do a string.Split on the '|' to separate the values. You could also store the data as xml, or maybe in JSON format, it is up to you.

However in general this is a bad idea as down the line you might want to query the data, eg all records with "1" as the first dropdown value and you won't be able to. It is much better to store data in different fields, or use a one to many relationship between the master record and all the fields that are relevant to it.
 
Share this answer
 
Don't.
It's a nasty thing to do because it causes major problems later - you have to "unpack" the single column each time you want to work with any part of it.
Replace the single column with three columns, and store each value separately. It may seem like a little more work, but it saves a heck of a lot of time and effort later.
 
Share this answer
 
There are two methods in which you can solve your problem.

1. Combine all (Radiabutton ,DropDownBox) value into one and pass that value to SQL query.

C#
string dropDownBoxValue1 = string.Empty;
string dropDownBoxValue2 = string.Empty;
string radioButton1Value = string.Empty;

string combineAllValue = string.Empty;


bool isChecked = radioButton1.Checked;


if(isChecked )
  radioButton1Value=radioButton1.Text;
  
  .......
  .......
  
dropDownBoxValue1 = Convert.ToString(DropDownBox1.SelectedValue);

dropDownBoxValue2 = Convert.ToString(DropDownBox2.SelectedValue);

combineAllValue=radioButton1Value +","+dropDownBoxValue1+","+dropDownBoxValue2 


Note :- combineAllValue pass this value to query String.


2. Combine all values in Stored Procedure and then store to table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900