-1

dtpGraduationYear is a TextBox that contains a date. I want to save the date from the textbox to database using Entity Framework.

private void btnSaveAll_Click(object sender, EventArgs e)
{
    //
    // tab Education
    //         
    var Education = new database.tblEmployeeQualification
    {
        EmployeeCode = Convert.ToInt32(txtCode.Text),
        UniversitiyCode = string.IsNullOrEmpty(txtEdUniversitiesNo.Text) ? (byte?)null : Convert.ToByte(txtEdUniversitiesNo.Text), 
        FauculityCode = string.IsNullOrEmpty(txtEdFacultyNo.Text) ? (byte?)null : Convert.ToByte(txtEdFacultyNo.Text), 
        QualificationsCode = string.IsNullOrEmpty(txtEdQualificationNo.Text) ? (byte?)null : Convert.ToByte(txtEdQualificationNo.Text), 
        SpecializationCode = string.IsNullOrEmpty(txtEdSpecializationNo.Text) ? (byte?)null : Convert.ToByte(txtEdSpecializationNo.Text), 
        EductionGrade = string.IsNullOrEmpty(txtEdGradeNo.Text) ? (byte?)null : Convert.ToByte(txtEdGradeNo.Text), 
        QualificationsTypeCode = string.IsNullOrEmpty(txtQualificationTypeNo.Text) ? (byte?)null : Convert.ToByte(txtQualificationTypeNo.Text), 
        GraduationYear = dtpGraduationYear.ToString("dd/MM/yyyy"),
        Note = txtEdNote.Text,
    };

    db.tblEmployeeQualifications.AddOrUpdate(Education);
    db.SaveChanges();
}

Error is here GraduationYear = dtpGraduationYear.ToString("dd/MM/yyyy"), error:

no overload for method 'tostring' takes 1 arguments

This is my model class:

public partial class tblEmployeeQualification
{
    public int EmployeeCode { get; set; }
    public Nullable<short> UniversitiyCode { get; set; }
    public Nullable<short> FauculityCode { get; set; }
    public Nullable<short> QualificationsCode { get; set; }
    public Nullable<short> SpecializationCode { get; set; }
    public Nullable<byte> EductionGrade { get; set; }
    public Nullable<byte> QualificationsTypeCode { get; set; }
    public Nullable<byte> MainEducationCode { get; set; }
    public Nullable<System.DateTime> GraduationYear { get; set; }
    public string Note { get; set; }

    public virtual tblEmployeeData tblEmployeeData { get; set; }
    public virtual tblEnglishLevel tblEnglishLevel { get; set; }
    public virtual tblFaculty tblFaculty { get; set; }
    public virtual tblMainEduaction tblMainEduaction { get; set; }
    public virtual tblQualification tblQualification { get; set; }
    public virtual tblQualificationType tblQualificationType { get; set; }
    public virtual tblSpecialization tblSpecialization { get; set; }
    public virtual tblUniversity tblUniversity { get; set; }
}
2

2 Answers 2

0

You can use:

GraduationYear = Convert.ToDateTime(dtpGraduationYear.Text.ToString());
Sign up to request clarification or add additional context in comments.

Comments

0

The line with the error you said is here:

GraduationYear = dtpGraduationYear.ToString("dd/MM/yyyy")

dtpGraduationYear you said is a TextBox. As with all your other textboxes, you need to read the Text property. As the error says:

no overload for method 'tostring' takes 1 arguments

That is, TextBox has a ToString() method, but it takes no arguments.

This is only half the answer though, your model expects GraduationDate to be Nullable<DateTime> - you'll need to convert the text to that type, probably using DateTime.Parse or DateTime.TryParse.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.