Example #1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            TestDBDataContext dc = new TestDBDataContext();

            if (textBoxNo.ReadOnly == false)//Insert
            {
                Employee obj = new Employee();
                obj.ID      = int.Parse(textBoxNo.Text);
                obj.Name    = textBoxName.Text;
                obj.City    = textBoxCity.Text;
                obj.Address = textBoxAddress.Text;
                dc.Employees.InsertOnSubmit(obj);
                dc.SubmitChanges();
                MessageBox.Show("Records inserted into the table");
            }
            else//Update
            {
                Employee obj = dc.Employees.SingleOrDefault(E => E.ID == int.Parse(textBoxNo.Text));
                obj.Name    = textBoxName.Text;
                obj.City    = textBoxCity.Text;
                obj.Address = textBoxAddress.Text;
                dc.SubmitChanges();
                MessageBox.Show("Record updated in table");
            }
        }
Example #2
0
        private void Form5_Load(object sender, EventArgs e)
        {
            TestDBDataContext dc = new TestDBDataContext();
            ISingleResult <GetEmployeesResult> tab = dc.GetEmployees("Godzilla");

            dataGridView1.DataSource = tab;
        }
Example #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            TestDBDataContext dc = new TestDBDataContext();
            //dataGridView1.DataSource = dc.Employees;
            Table <Employee> tab = dc.Employees;

            dataGridView1.DataSource = tab;
        }
Example #4
0
        private void Form7_Load(object sender, EventArgs e)
        {
            dc = new TestDBDataContext();
            //var tab = from E in dc.Emps select E;
            //dataGridView1.DataSource = tab;
            //OR
            dataGridView1.DataSource = from E in dc.Emps select E; //To retrieve all data
            var tab = from E in dc.Emps select new { E.Job };      //To retrieve Job information

            comboBox1.DataSource    = tab.Distinct();              //Binding only unique data to combobox using Distinct();
            comboBox1.DisplayMember = "Job";                       //To display exact data from "Job" column into combobox
            comboBox1.SelectedIndex = -1;                          //So that combobox doesn't selects item by default
            flag = true;
        }
Example #5
0
 private void LoadData()
 {
     dc = new TestDBDataContext();
     dgView.DataSource = dc.Employees;
 }
Example #6
0
 private void Form2_Load(object sender, EventArgs e)
 {
     dc   = new TestDBDataContext();
     Emps = dc.Employees.ToList();
     ShowData();
 }
Example #7
0
 private void Form6_Load(object sender, EventArgs e)
 {
     dc = new TestDBDataContext();
 }