コード例 #1
0
        private void InsertChanges()
        {
            try
            {
                string   strInCompanyNum = ViewState["CompanyNum"].ToString();
                int      intCompanyNum   = int.Parse(strInCompanyNum);
                string   strFname        = txtFName.Text;
                string   strLname        = txtLName.Text;
                string   strGender       = rblGender.SelectedValue;
                string   strEmpId        = txtEmployeeId.Text;
                int      empId           = int.Parse(strEmpId);
                string   strNewBirthDate = dt2.Value;
                DateTime birthDate;
                birthDate = new DateTime(Convert.ToInt16(strNewBirthDate.Substring(0, 4)), Convert.ToInt16(strNewBirthDate.Substring(5, 2)), Convert.ToInt16(strNewBirthDate.Substring(8, 2)));



                using (var db = new TrustCompanyEntities())
                {
                    var employees = db.Set <CompanyEmployee>();
                    employees.Add(new CompanyEmployee {
                        CNum = intCompanyNum, Fname = strFname, Lname = strLname, Gender = strGender, EmployeeId = empId, BirthDate = birthDate
                    });

                    db.SaveChanges();
                    lblRowInsert.Visible = true;
                }
            }
            catch (Exception ex)
            {
                lblRowInsert.Visible = true;
                lblRowInsert.Text    = ex.Message;
            }
        }
コード例 #2
0
        private void InsertChanges()
        {
            try
            {
                string newstrCompanyNum = txtCompanyNum.Text;
                int    newintCompanyNum = int.Parse(newstrCompanyNum);
                string strCompanyName   = txtCompanyName.Text;
                string strAddress       = txtAddress.Text;
                string strTelephone     = txtTelephone.Text;


                using (var db = new TrustCompanyEntities())
                {
                    var companies = db.Set <Company>();
                    companies.Add(new Company {
                        CNum = newintCompanyNum, Cname = strCompanyName, Address = strAddress, Telephone = strTelephone
                    });

                    db.SaveChanges();
                    lblRowInsert.Visible = true;
                }
            }
            catch (Exception ex)
            {
                lblRowInsert.Visible = true;
                lblRowInsert.Text    = ex.Message;
            }
        }