开发者

How to store Multiple radio button and check box values in sqlserver database using Asp.net?

开发者 https://www.devze.com 2023-03-04 01:50 出处:网络
I am making database using sqlserver2008. Which data type I should choose? In php I use ENUM and in value field I put like that \'Male\',\'Female\'. what is the way in sqlserver to create radio button

I am making database using sqlserver2008. Which data type I should choose? In php I use ENUM and in value field I put like that 'Male','Female'. what is the way in sqlserver to create radio button and check box field? And how to insert these in sqldatabase? I have two gender radio button with different ids so I apply check before insertion i.e. connection.open(); string gen = ""; if(rdm.Checked == true) { string gen ="Male"; } else if (rdf.Checked == true) { string gen = "Fema开发者_StackOverflowle"; } and in insert value field I just put +gen+ but I receive error: Error 1 A local variable named 'gen' cannot be declared in this scope because it would give a different meaning to 'gen', which is already used in a 'parent or current' scope to denote something else


I usually store dotnet Enums as integers (smallint) in SQL server, sometimes when the database is queried directly by users I use varchar values for readability. Both can easily be converted back to Enums.


I will commonly create a code table in the database to represent my .net enums. Then the associated field in the main data table is just an int with a FK constraint to the code table.

This allows for compact storage and transmission of the data, ensures that no out of range values are entered into the database, and if anyone needs to query the db directly they can join to the code tables to find out what the integers mean.

0

精彩评论

暂无评论...
验证码 换一张
取 消