using System;
using System.Windows.Forms;
//-------------------------------------
using System.Data;
using System.Data.SqlClient;

namespace _17_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string strConn = "Server=.;" + "DataBase=MyTestDB;" +
                         "Integrated Security=True";
        
        SqlConnection sCon;
        SqlCommand sc;

        private void UpdateRecord()
        {
            string strUpdate = string.Format("Update Info Set Last_Name='{0}', First_Name='{1}', Sex='{2}', Average='{3}', Number_of_Unit='{4}' Where Student_Number='{5}'", textBox2.Text.Trim(), textBox3.Text.Trim(), checkBox1.Checked, Convert.ToSingle(textBox4.Text.Trim()), Convert.ToInt32(textBox5.Text.Trim()), Convert.ToInt32(textBox1.Text.Trim()));

            sCon = new SqlConnection();
            sCon.ConnectionString = strConn;

            sc = new SqlCommand();
            sc.CommandType = CommandType.Text;
            sc.CommandText = strUpdate;
            sc.Connection = sCon;
            sc.Connection.Open();
            sc.ExecuteNonQuery();
            sc.Connection.Close();

            MessageBox.Show("Record Updated");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UpdateRecord();
        }
    }
}