将单选按钮值插入sqlserver数据库。 [英] Inserting radio button values into sqlserver database.
本文介绍了将单选按钮值插入sqlserver数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个RadioButtons( MaleRB
和 FmaleRB
)在我的数据库中我有两列男性
和女性
,如果我选择 MaleRB
,它应该更新为我的数据库中有1个,即男性
列,女性栏目和副词中有0个。
任何人都可以帮忙请告诉我。
I have two RadioButtons(MaleRB
and FmaleRB
) And in my data base I have two column Male
and female
, If I select MaleRB
, It should get updated as 1 in my database ie, in Male
column and 0 in Female column And Viceversa.
Can any one help me out please.
推荐答案
在C#代码中有两列参数。
根据表格中选择的值,你可以使用checked
属性来确定需要在数据库中插入的内容。
示例
Have a parameter for the two columns in the C# code.
Based on value chosen in the form, you can use thechecked
property to figure out what needs to be inserted in the database.
Example
if(MaleRB .Checked== "1")
SqlDataSource1.UpdateParameters[0].DefaultValue = "True";
else
SqlDataSource1.UpdateParameters[0].DefaultValue = "False";
您知道,最好的解决方案是在表格中添加一个性别标志。字段的规范化应该是每个人的惯例。 0表示男性,1表示女性或反之。有了这个,你在更新性别状态时会有较少的逻辑。
干杯!
Eduard
You know, the best solution for this is to have a single gender flag into your table. Normalization of fields should be a practice to everyone. 0 for male and 1 for female or viceversa. With that, you would have lesser logic in updating gender status.
Cheers!
Eduard
string rbValue;
if (MaleRb.Checked == true)
{
rbValue = "1";
mycommand.Parameters.AddWithValue("@Gender", rbValue);
}
if (FmaleRb.Checked == true)
{
rbValue = "0";
mycommand.Parameters.AddWithValue("@Gender", rbValue);
}
可以使用此解决您的问题
Can solve your problem using this
这篇关于将单选按钮值插入sqlserver数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文