Exemple #1
0
        private void LinqToSQL_4_Load(object sender, EventArgs e)
        {
            UniversityData = new UniversityDataDataContext();

            var Etable = from E in UniversityData.Emps orderby E.Sal select E;

            dataGridView1.DataSource = Etable;

            var Cbox = from E in UniversityData.Emps select new { E.Job };

            comboBox1.DataSource    = Cbox.Distinct();
            comboBox1.DisplayMember = "Job";
            comboBox1.SelectedIndex = -1;
            flag = true;

            /*
             * //////ami chaisilam combobox e click korle sort hobe but error ach
             * List<string> citem = new List<string> { "Empno", "Ename", "Job", "Mgr", "HireDate", "Sal", "Comm", "Deptno", "Dept" };
             * citem.Sort();
             * var Cboxo = citem;
             * comboBox2.DataSource = Cboxo;
             * comboBox2.SelectedIndex = -1;
             * flag1 = true;
             */
        }
        private void LinqToSQL_3_Load(object sender, EventArgs e)
        {
            universityData = new UniversityDataDataContext();

            ///Select all from Teacher
            ISingleResult <Teacher_SelectResult> selectResults1 = universityData.Teacher_Select();

            dataGridView1.DataSource = selectResults1;

            ///Select all from Teacher where Department = EEE
            //ISingleResult<Teacher_SpScResult> selectResults2 = universityData.Teacher_SpSc(null);
            ISingleResult <Teacher_SpScResult> selectResults2 = universityData.Teacher_SpSc("EEE");

            dataGridView2.DataSource = selectResults2;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ///Jehetu UniversityDataDataContext bar bar use korbo tai ata class er moddhe decalare korlam opore
            //UniversityDataDataContext universityData = new UniversityDataDataContext(); //mainly ata holo database er sathe connection establish kora
            universityData = new UniversityDataDataContext();

            ///dataGridView er moddhe table ta assign korlam process-1
            Table <Student> StudentTable = universityData.Students;

            dataGridView1.DataSource = StudentTable;

            ///dataGridView er moddhe table ta assign korlam process-2
            //dataGridView1.DataSource = universityData.Students;

            ///universityData database er Students table ta ke list e convert korlam
            students = universityData.Students.ToList();
            TableData();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            UniversityDataDataContext universityData = new UniversityDataDataContext();//conn established

            if (textBox1.ReadOnly == false)
            {
                Student student = new Student();
                student.Id     = Convert.ToInt32(textBox1.Text); // or, student.Id = int.Parse(textBox1.Text);
                student.S_Name = textBox2.Text;
                student.Reg    = textBox3.Text;
                universityData.Students.InsertOnSubmit(student); //inserting on student table as a row
                universityData.SubmitChanges();                  //comminting the changes
                MessageBox.Show("Record inserted into the Student Table");
            }
            else
            {
                Student student = universityData.Students.SingleOrDefault(E => E.Id == int.Parse(textBox1.Text));
                student.Id     = int.Parse(textBox1.Text);
                student.S_Name = textBox2.Text;
                student.Reg    = textBox3.Text;
                universityData.SubmitChanges();//comminting the changes
                MessageBox.Show("Record updated into the Student Table");
            }
        }
 private void LoadTable()
 {
     universityData           = new UniversityDataDataContext();
     dataGridView1.DataSource = universityData.Students;
 }