how to insert RadioButton into sql server uwp c#

Javier R 211 Reputation points
2021-02-23T18:44:23.34+00:00

how to insert RadioButton into sql server uwp ? having two options. <RadioButton x:Uid="RBVaron" x:Name="radiovaron" GroupName="Gener"/>

Universal Windows Platform (UWP)
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,318 questions
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Abdulhakim M. Elrhumi 356 Reputation points
    2021-02-23T18:56:14.473+00:00

    Hi

    /****** Object:  StoredProcedure [dbo].[spInsertIntoEmployee]    Script Date: 2021-02-23 20:49:33 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    Create Proc [dbo].[spInsertEmployee]
    
    
    @Emp_Number BigInt, 
    @EmpName nvarchar(50),
    @Sex int  -- RadioButton
    AS
    Begin
        Declare @EmpID int
    
    
        Select @EmpID=[dbo].[Employee].EmpID from [dbo].[Employee] where [dbo].[Employee].Emp_Number=@Emp_Number
        if(@EmpID is null)
                Begin
    
                    INSERT INTO [dbo].[Employee]
                       ([Emp_Number]
                       ,[EmpName]
                       ,[Sex]
    )
                 VALUES
                       (@Emp_Number
                       ,@EmpName
                       ,@Sex)
                       Select @EmpID=SCOPE_IDENTITY()
                End
        ELSE
            BEGIN
                UPDATE [dbo].[Employee]
                       SET    [EmpName]=@EmpName  ,[Sex]=@Sex
                 WHERE EmpId=@EmpId
            END
    End
    Go
    

    Best Regards.
    Please remember to mark the replies as answers if they help.

    0 comments No comments

  2. AryaDing-MSFT 2,916 Reputation points
    2021-02-24T05:52:57.167+00:00

    Hi,

    Welcome to Microsoft Q&A!

    If you want to insert the value of selected RadioButton into the sql database, you could follow the steps below to do this.

    (1) Place two radio button in a stackpanel named radiobuttonPanel, then find the selected radio button.

    RadioButton radiobutton= radiobuttonPanel.Children.OfType<RadioButton>().FirstOrDefault(r => r.IsChecked == true);  
    String content=radiobutton.Content.ToString();  
    

    (2) Please refer to the following code to write insert command. More SQL Server database operations could be found here.

    using (SqlCommand cmd = conn.CreateCommand())  
       {  
    // option is the column name of the column you want to insert  
          cmd.CommandText = “insert into tablename (option) values (content)”;  
    cmd.ExecuteNonQuery();  
    }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. Javier R 211 Reputation points
    2021-02-24T18:46:22.373+00:00
    using (SqlConnection conn = new SqlConnection())
                {
    
                    using (SqlCommand cmd = new SqlCommand(SqlString, conn))
                        {
                        cmd.CommandType = CommandType.Text; 
                            cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@DuoDate", txtName.Text );
                        cmd.Parameters.AddWithValue("@PetName",  txtName.Text);
                        cmd.Parameters.AddWithValue("@PetRace",  txtRace.Text );
                        cmd.Parameters.AddWithValue("@PetColor", txtColor.Text);
                        cmd.Parameters.AddWithValue("PetChip", txtCchip.Text);
    
                        if(radioMale.IsChecked == true)
                        {
                            cmd.Parameters.AddWithValue("@PetSex", "RBVaron");
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@PetSex", "RBHembra");
                        }
    
                            if(radioyessterile.IsChecked == true)
                        {
                            cmd.Parameters.AddWithValue("@PetSterile","RBsteriles" );
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@PetSterile", "RBsteriles");
                        }
    
    
    
    
                        conn.Open();
                            cmd.ExecuteNonQuery();
    
    
                        }
    

  4. Javier R 211 Reputation points
    2021-02-28T19:15:53.987+00:00
     RadioButton rb = RadioButtonPanel.Children.OfType<RadioButton>().FirstOrDefault(r => r.IsChecked == true);
                RadioButton rb1 = RadioButtonPanel1.Children.OfType<RadioButton>().FirstOrDefault(r => r.IsChecked == true);
    
                const  string  SqlString = "insert into PetItem(DuoDate,PetName,PetRace, PetColor, PetChip,PetGender,PetSterile) values (@duoDate,@petName,@petRace,@petColor,@PetChip,@petGender,@petSterile)";
                try
                {
    
    
                    using (SqlConnection conn = new SqlConnection(connectionString))
                    {
                        conn.Open();
    
                        if (conn.State == System.Data.ConnectionState.Open)
                        {
                            using (SqlCommand cmd = conn.CreateCommand())
                            {
    
                                cmd.CommandText = SqlString;
                                cmd.Parameters.Clear();
                                cmd.Parameters.Add("@duoDate", SqlDbType.Date).Value = DateNac;
                                cmd.Parameters.Add("@petName", SqlDbType.Char, 40).Value = txtName.Text;
                                cmd.Parameters.Add("@petRace", SqlDbType.Char, 40).Value = txtRace.Text;
                                cmd.Parameters.Add("@petColor", SqlDbType.Char, 40).Value = txtColor.Text;
                                cmd.Parameters.Add("@petChip", SqlDbType.VarChar, 40).Value = txtChip.Text;
                                cmd.ExecuteNonQuery();
    
    
                            }
                        }
                    }
                }
    
                catch(Exception ex)
                {
                    //mesagedialog
                }
            }
    
    0 comments No comments

  5. Javier R 211 Reputation points
    2021-03-31T13:16:16.093+00:00

    I have a problem with the RadioButton in Sql Server.