public int Insert(Student s)
        {
            //int res = -1;

            //this.cmd.CommandText = "insert into student (Name,Roll,Age) values(@Name,@Roll,@Age)";
            //this.cmd.Parameters.AddWithValue("@Name", s.Name);
            //this.cmd.Parameters.AddWithValue("@Age", s.Age);
            //this.cmd.Parameters.AddWithValue("@Roll", s.Roll);

            //Connect();

            //try
            //{
            //    res = cmd.ExecuteNonQuery();

            //}
            //catch (SqlException se)
            //{
            //    Console.WriteLine(se.Message);
            //    res = -1;
            //}

            //this.Disconnect();

            //return res;

            string query = "insert into student (Name,Roll,Age) values('"+s.Name+"',"+s.Roll+","+s.Age+")";

            int result=this.InsertUpdateDelete(query);
            return result;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Student s= new Student();
            s.Name = NameTextbox.Text;
            s.Roll = Convert.ToInt32(RollTextbox.Text);
            s.Age = Convert.ToInt32(AgeTextbox.Text);
            s.Sn = Convert.ToInt32(SnTextbox.Text);

            StudentDb sdb=new StudentDb();
            int result=sdb.Update(s);

            if(result==-1)
            {
                MessageBox.Show("Couldnt be updated");
            }

            else
            {
                MessageBox.Show(result+" Row updated");
            }

            LoadListView();
        }
        public int Update(Student s)
        {
            //int res = -1;

            //this.cmd.CommandText = "Update Student set Name=@Name, Roll=@Roll,Age=@Age where SN=@SN";
            //this.cmd.Parameters.AddWithValue("@Name", s.Name);
            //this.cmd.Parameters.AddWithValue("@Age", s.Age);
            //this.cmd.Parameters.AddWithValue("@Roll", s.Roll);
            //this.cmd.Parameters.AddWithValue("@SN", s.Sn);

            //Connect();

            //try
            //{
            //    res = cmd.ExecuteNonQuery();

            //}
            //catch (SqlException se)
            //{
            //    Console.WriteLine(se.Message);
            //    res = -1;
            //}

            //this.Disconnect();

            //return res;
            //"update student set name='"+s.Name+"', roll="+s.Roll=", age=20 where sn=1"
            string query = "Update Student set Name='"+s.Name+"', Roll="+s.Roll+",Age="+s.Age+" where SN="+s.Sn;

            int result=this.InsertUpdateDelete(query);
            return result;
        }
        public List<Student> SelectAll()
        {
            List<Student> list=new List<Student>();

            cmd.CommandText = "select * from Student";

            this.Connect();

            try
            {
                reader=cmd.ExecuteReader();
            }

            catch(SqlException se)
            {
                Console.WriteLine(se.Message);
            }

            while(reader.Read())
            {
                Student temp=new Student();
                temp.Sn = Convert.ToInt32(reader["SN"]);
                temp.Name = Convert.ToString(reader["Name"]);
                temp.Age = Convert.ToInt32(reader["Age"]);
                temp.Roll = Convert.ToInt32(reader["Roll"]);
                list.Add(temp);
            }
            return list;
        }
        private void button4_Click(object sender, EventArgs e)
        {
            Student s=new Student();
            s.Name = NameTextbox.Text;
            s.Roll = Convert.ToInt32(RollTextbox.Text);
            s.Age = Convert.ToInt32(AgeTextbox.Text);

            StudentDb sdb=new StudentDb();
            int result=sdb.Insert(s);

            if(result==-1)
            {
                MessageBox.Show("Data cannot be inserted");

            }

            else
            {
                MessageBox.Show(result +"rows inserted");
            }

            LoadListView();
        }