Example #1
0
 protected void btnInsert_Click(object sender, EventArgs e)
 {
     try
     {
         StudentsDS.InsertParameters["St_Id"].DefaultValue      = studId.Text;
         StudentsDS.InsertParameters["St_Fname"].DefaultValue   = studFName.Text;
         StudentsDS.InsertParameters["St_Lname"].DefaultValue   = studLName.Text;
         StudentsDS.InsertParameters["St_Address"].DefaultValue = studAddress.Text;
         StudentsDS.InsertParameters["St_Age"].DefaultValue     = studAge.Text;
         StudentsDS.InsertParameters["Dept_Id"].DefaultValue    = studDepartment.SelectedValue;
         StudentsDS.Insert();
         studId.Text = studFName.Text = studLName.Text = studAddress.Text = studAge.Text = "";
         GridView1.DataBind();
         Master.ShowAlert("Success", "Row inserted successfully");
     }
     catch (Exception)
     { Master.ShowAlert("Error", "Cannot insert a row with the provided data"); }
 }
Example #2
0
        protected void AddStudentBTN_Click(object sender, EventArgs e)
        {
            MembershipCreateStatus createStatus;
            MembershipUser         newUser = Membership.CreateUser(st_UsernameTB.Text, st_PasswordTB.Text, st_EmailTB.Text, "Default Question", "Default Answer", true, out createStatus);

            switch (createStatus)
            {
            case MembershipCreateStatus.Success:
                AddStudentResultLB.Text = "<i class='icon-ok'></i>  The student account was successfully created!";
                break;

            case MembershipCreateStatus.DuplicateUserName:
                AddStudentResultLB.Text = "<i class='icon-remove'></i>  There already exists a student with this username.";
                break;

            case MembershipCreateStatus.DuplicateEmail:
                AddStudentResultLB.Text = "<i class='icon-remove'></i>  There already exists a student with this email address.";
                break;

            case MembershipCreateStatus.InvalidEmail:
                AddStudentResultLB.Text = "<i class='icon-remove'></i>  The email address you provided in invalid.";
                break;

            case MembershipCreateStatus.InvalidAnswer:
                AddStudentResultLB.Text = "<i class='icon-remove'></i>  The security answer was invalid.";
                break;

            case MembershipCreateStatus.InvalidPassword:
                AddStudentResultLB.Text = "<i class='icon-remove'></i>  The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character.";
                break;

            default:
                AddStudentResultLB.Text = "<i class='icon-remove'></i>  There was an unknown error; the user account was NOT created.";
                break;
            }
            if (createStatus == MembershipCreateStatus.Success)
            {
                StudentsDS.Insert();
                StudentsGridView.DataBind();
            }
        }