Saturday, 23 July 2011

radio button with sqldata


 private void button1_Click(object sender, EventArgs e)
        {
            string gender;
            if (radioButton1.Checked)
            {
                gender = radioButton1.Text.ToString();
            }
            else
            {
                gender = radioButton2.Text.ToString();
            }
            SqlConnection cn = new SqlConnection("server=WEBNET;database=scott;user=sa;password=aptech");
            string insert;
            insert = "insert into student values('" + textBox1.Text + "','" + textBox2.Text + "','" + gender + "')";
            SqlCommand comm = new SqlCommand(insert, cn);
            cn.Open();
            if (MessageBox.Show("Do want to insert record? ","Winform",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning)==DialogResult.OK)
            {
                comm.ExecuteNonQuery();
            }
                cn.Close();
        }

No comments:

Post a Comment