Beispiel #1
0
    //funtion for updating records
    void Update()
    {
        //create an insatnce of the address book
        CarClasses.clsStaffCollection StaffBook = new CarClasses.clsStaffCollection();
        //validate the data on the web form
        String Error = StaffBook.ThisStaff.Valid(txtStaffName.Text, txtStaffAddress.Text, txtStaffTelNumber.Text, txtDateJoined.Text, txtStaffID.Text);

        //if the data is OK then add it to the object
        if (Error == "")
        {
            //find the record to update
            StaffBook.ThisStaff.Find(StaffID);
            //get the data entered by the user
            StaffBook.ThisStaff.StaffName      = txtStaffName.Text;
            StaffBook.ThisStaff.StaffAddress   = txtStaffAddress.Text;
            StaffBook.ThisStaff.StaffTelNumber = txtStaffTelNumber.Text;
            StaffBook.ThisStaff.DateJoined     = Convert.ToDateTime(txtDateJoined.Text);
            StaffBook.ThisStaff.StaffID        = Convert.ToInt32(txtStaffID.Text);
            //add the record
            StaffBook.Update();
            //all done redirect back to the main page
            Response.Redirect("DefaultStaff");
        }
        else
        {
            //report and error
            lblError.Text = "There was problems with data entered" + Error;
        }
    }
 void DisplayStaff()
 {
     //create an instance of the staff collection
     CarClasses.clsStaffCollection Staff = new CarClasses.clsStaffCollection();
     //set the data source
     lstStaff.DataSource = Staff.StaffList;
     //set the name of the primary key
     lstStaff.DataValueField = "StaffID";
     //set the data field to display
     lstStaff.DataTextField = "StaffName";
     //bind the data to the list
     lstStaff.DataBind();
 }