How to insert when I have two radiobutton for Gender introduce on sql serveruwp c#

Javier R 211 Reputation points
2021-04-22T14:15:10.49+00:00

he question is whether I have two or more radiobuttons the same group in this case RadioMale and Radio Female. The value you enter in the table can be one of two petgender options in the Sql statement.

<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"/>

cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioMale.Content;
cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioFemale.Content;
Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Peter Fleischer (former MVP) 19,231 Reputation points
    2021-04-24T15:55:19.067+00:00

    Hi,
    if in the GroupBox "GroupSex" are only 2 RadioButtons you can use only one instruction instead of two:

      cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = (radioMale.IsChecked) ? radioMale.Content : radioFemale.Content;
    
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Javier R 211 Reputation points
    2021-04-24T15:42:33+00:00

    this is the soluction if(radioMale.IsChecked == true) { rbGender = "0"; cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioMale.Content; } if(radioFemale.IsChecked == true) { rbGender = "1"; cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioFemale.Content; }

    1 person found this answer helpful.
    0 comments No comments