Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
objStudent.UserName = GetUserName();
          objStudent.Password = _objIBALCommonFunction.GenerateRandomString(8);//_objIBALCommonFunction.Encrypt(_objIBALCommonFunction.GenerateRandomString(8));
          objStudent.FirstName = txtFirstName.Text.ToString().Trim().Replace("'", "");
          objStudent.RollNo = txtRollNo.Text.ToString().Trim().Replace("'", "");
          objStudent.LastName = txtLastName.Text.ToString().Trim().Replace("'", "");
          if (rbGenderFemale.Checked)
          {
              gen = 'F';
          }
          else
          {
              gen = 'M';
          }
          objStudent.Gender = gen.ToString();
          objStudent.Email = txtEmail.Text.ToString().Trim().Replace("'", "");
          objStudent.Phone = txtPhone.Text.ToString().Trim().Replace("'", "");
          objStudent.Mobile = txtMobile.Text.ToString().Trim().Replace("'", "");
          objStudent.Address = txtAddress.Text.ToString().Trim().Replace("'", "");
          try
          {
          //objStudent.DOB = txtDOB.Text;
            objStudent.DOB = DateTime.ParseExact(txtDOB.Text, "dd/MM/yyyy", null).ToString();
            //objStudent.DOB = txtDOB.Text.ToString().Trim().Replace("'", "");
          }
          catch (Exception ex)
          {
              lblError.Text = "Date of Birth not in proper format !";
              return;
          }
          objStudent.BloodGroup = txtBloodGroup.Text.ToString().Trim().Replace("'", "");
          try
          {
            objStudent.AdmissionDate = DateTime.ParseExact(txtAdmissionDate.Text, "dd/MM/yyyy", null).ToString();
            // objStudent.AdmissionDate = txtAdmissionDate.Text.ToString().Trim().Replace("'", "");
          }
          catch (Exception ex)
          {
              lblError.Text = "Admission Date not in proper format !";
              return;
          }

          objStudent.CityId = Convert.ToInt32(ddlCity.SelectedValue);
          objStudent.StateId = Convert.ToInt32(ddlState.SelectedValue);
          objStudent.Pincode = txtPincode.Text.ToString().Trim().Replace("'", "");

          if (txtPhoto.PostedFile.ContentLength > 0)
          {
              string fullPath = Server.MapPath("Image/" + objStudent.UserName + Path.GetExtension(txtPhoto.PostedFile.FileName));
              objStudent.ImagePath = System.Configuration.ConfigurationManager.AppSettings["ImageUrl"].ToString() + "Module-Customer/Image/" + objStudent.UserName + Path.GetExtension(txtPhoto.PostedFile.FileName);
              txtPhoto.PostedFile.SaveAs(fullPath);
          }
          else
          {
              if (gen == 'M') { objStudent.ImagePath = System.Configuration.ConfigurationManager.AppSettings["ImageUrl"].ToString() + "Module-Customer/Image/male_user.png"; }
              else { objStudent.ImagePath = System.Configuration.ConfigurationManager.AppSettings["ImageUrl"].ToString() + "Module-Customer/Image/female_user.png"; }
          }
          objStudent.Theme = ddlTheme.SelectedValue;
          objStudent.Menu = ddlMenu.SelectedValue;
          objStudent.Description = txtDescription.Text.ToString().Trim().Replace("'", "");
          objStudent.InstituteName = txtInstituteName.Text.ToString().Trim().Replace("'", "");
          objStudent.ClassName = txtClassName.Text.ToString().Trim().Replace("'", "");
          objStudent.ObtainedMarks = txtObtainedMarks.Text.ToString().Trim().Replace("'", "");
          objStudent.YearPassing = ddlYearPassing.SelectedValue;
          objStudent.IsActive = 1;
          objStudent.IsDeleted = 0;
          objStudent.BAId = Convert.ToInt32(Session["BAId"].ToString());
Posted
Comments
VishwaKL 10-Dec-12 5:00am    
Can you spot which line giving error

1 solution

May be your data type is datetime of DOB. So, you have to supply datetime format data.

you can change this line:

C#
try
        {
        //objStudent.DOB = txtDOB.Text;
            objStudent.DOB=Convert.ToDateTime(DateTime.Parse("13/1/2012").ToString("dd/MM/yyyy"));
          //objStudent.DOB = txtDOB.Text.ToString().Trim().Replace("'", "");
        }
        catch (Exception ex)
        {
            lblError.Text = "Date of Birth not in proper format !";
            return;
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900