如何将 RadioButton 的内容插入 SQL UWP C# 服务器?

How to insert the content of a RadioButton into SQL Server for UWP C#?

如何将内容“男性”插入 SQL 服务器,并将 RadioButton 的内容“女性”插入 table。

<RadioButton x:Uid="RBVaron" x:Name="radioMale"  Grid.Row="22" Grid.Column="0" FontSize="{StaticResource SmallFontSize}" GroupName="GroupSex" />

<RadioButton x:Uid="RBHembra" x:Name="radioFemale"   Margin="150,-32,0,0"  Grid.Row="22" Grid.Column="0"  FontSize="{StaticResource SmallFontSize}" GroupName="GroupSex"/>

代码 c# sql 服务器:

cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioMale;

class.cs

public string  PetGender { get; set; }

根据您提供的代码,我观察到您没有给出 RadioButton 控件的 Content 属性 值。所以两个RadioButton控件的内容都是空白的。 radioMaleRadioButton 控件的 Name。您可以通过此名称 radioMale.

引用 RadioButton 控件

如果要将RadioButton的内容插入SQL服务器,需要给RadioButton控件一个内容。然后使用 RadioButton 控件的 Name 获取内容值。

例如:

设置 RadioButton 控件的 Content 属性 的值:

<RadioButton x:Uid="RBVaron" x:Name="radioMale"  Grid.Row="22" Grid.Column="0"  GroupName="GroupSex" Content="Male"/>
<RadioButton x:Uid="RBHembra" x:Name="radioFemale"   Margin="150,-32,0,0"  Grid.Row="22" Grid.Column="0" GroupName="GroupSex" Content="Female"/>

获取 RadioButton 控件的 Content 属性 的值并将其插入 SQL 服务器:

cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioMale.Content;