示例#1
0
 // Constructor
 public MainPage()
 {
     InitializeComponent();
     using (employeeContext context = new
                                      employeeContext(employeeContext.dbconstring))
     {
         if (!context.DatabaseExists())
         {
             context.CreateDatabase();
         }
     }
 }
示例#2
0
 //define a method known as add employee
 public void addEmployee(string ename, string etitle,
                         string position, string gender, double salary)
 {
     //we shall use the employeecontext connection
     using (employeeContext context = new employeeContext(employeeContext.dbconstring))
     {
         //creat a new instance of the class employee
         employee e = new employee();
         //assign fields values
         e.empname  = ename;
         e.gender   = gender;
         e.position = position;
         e.salary   = salary;
         e.title    = title;
         //submit for insertion
         context.tblEmployee.InsertOnSubmit(e);
         //save the records
         context.SubmitChanges();
     }
 }