コード例 #1
0
ファイル: Form1.cs プロジェクト: hemtros/DatabaseWinheritance
        public void LoadListView()
        {
            listView1.Items.Clear();
            StudentDb stdb = new StudentDb();
            List<Student> list = stdb.StdSelectAll();

            foreach (Student s in list)
            {
                ListViewItem row = new ListViewItem();    //row is created every time the loop runs
                row.Text = s.SN.ToString();
                row.SubItems.Add(s.Name);
                row.SubItems.Add(s.Age.ToString());
                row.SubItems.Add(s.Roll.ToString());
                listView1.Items.Add(row);  //at end of these statements row is added and the variable is destroyed and collected by garbage collector

            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: hemtros/DatabaseWinheritance
        private void button4_Click(object sender, EventArgs e)
        {
            Student s=new Student();
               // s.SN = Convert.ToInt32(SnTextbox.Text);
            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("couldn't be inserted");
            }

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