ASp.net

Monday, September 14, 2015

How to Use Radio Button in C#

1 comment:

  1. using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;


    namespace WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    GetData();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
    GetData();
    }

    String Gender;

    private void button1_Click(object sender, EventArgs e)
    {
    try
    {
    SqlConnection con = new SqlConnection(@"Data Source=I:\C3 soft\WindowsFormsApplication2\WindowsFormsApplication2\Database1.sdf");
    con.Open();
    string qry = string.Format("Insert into Customer(Name, Age,Gender,Mobile) Values ('{0}','{1}','{2}','{3}')", textBox1.Text, textBox2.Text, Gender , textBox4.Text);
    SqlCommand cmd = new SqlCommand(qry, con);
    cmd.ExecuteReader();
    con.Close();
    MessageBox.Show("Successfully saved");
    GetData();

    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    }


    public void GetData()

    {
    try
    {
    SqlConnection con = new SqlConnection(@"Data Source=I:\C3 soft\WindowsFormsApplication2\WindowsFormsApplication2\Database1.sdf");
    con.Open();
    SqlCommand cmd = new SqlCommand("Select * From Customer", con);
    SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    dataGridView1.Rows.Clear();
    while ((rdr.Read() == true))
    {
    dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4]);
    }
    con.Close();
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }


    }

    private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {
    Gender = "Male";
    }

    private void radioButton2_CheckedChanged(object sender, EventArgs e)
    {
    Gender = "Female";
    }



    }
    }

    ReplyDelete

MM Online Express | Best product Review and Online Marketing site

MM Online Express | Best product Review and Online Marketing site