Sample example without any validations......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace RadioButtonEx
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"data source = .; initial catalog = DBName ; user id=testLogin ;password =pwd@1234 ");
SqlCommand com;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnRegister_Click(object sender, EventArgs e)
{
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into WindowRadioButton values(@Name, @Address, @Age, @Gender)";
com.Parameters.Clear();
int gender = (rbtnMale.Checked == true) ? 1 : 0; // This is for storing gender value into data base... 1= Male , 0 = Female
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Address", txtName.Text);
com.Parameters.AddWithValue("@Age", txtAge.Text);
com.Parameters.AddWithValue("@gender", gender);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data entered successfully!!!");
clear();
}
private void clear()
{
txtName.Text = "";
txtAddress.Text = "";
txtAge.Text = "";
}
}
}
Controls are:
3 Text Boxes: txtName, txtAddress, txtAge,
2 Radio Buttons: rbtnFemale, rbtnMale
1 Button : btnRegister
Table Structure:
CREATE TABLE WindowRadioButton
( Name VARCHAR(20),
Address VARCHAR(50),
Age INT,
Gender INT)
Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif
Srinibaschampati, if this helps please login to Mark As Answer. | Alert Moderator