question

Jramos avatar image
0 Votes"
Jramos asked PeterFleischer-3316 edited

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

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;
windows-uwp
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Female and Male are mutex, Why not use ToggleSwitch control to integrate them?

0 Votes 0 ·

Here the problem is in the PetGender that has to take one of the two Male or Female values for the database.

0 Votes 0 ·

So, your problem is where to call the following lines right?

 cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioMale.Content;
  cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = radioFemale.Content;
0 Votes 0 ·
Show more comments
PeterFleischer-3316 avatar image
2 Votes"
PeterFleischer-3316 answered PeterFleischer-3316 edited

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.



cmd.Parameters.Add("@petGender", SqlDbType.VarChar, 40).Value = (bool)radioMale.IsChecked ? radioMale.Content : radioFemale.Content;








0 Votes 0 ·

Ok, I corrected my answer.

0 Votes 0 ·
Jramos avatar image
1 Vote"
Jramos answered

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; }

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.