Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:17:27+00:00 2026-06-13T10:17:27+00:00

Using Entity Framework, I have a Combobox showing a list of data retrieved from

  • 0

Using Entity Framework, I have a Combobox showing a list of data retrieved from a database.

using System;  //I removed the other using statements here to preserve space

namespace ExTea_BackEnd
{
    public partial class frmAddBreakdown : Form
    {
        ExTeaEntities Breakdowns;
        Breakdown_Type BreakdownTypes;

        public frmAddBreakdown()
        {
            InitializeComponent();
        }

        private void cmbBreakdownType_SelectedIndexChanged(object sender, EventArgs e)
        {
            Breakdown_Type breakdownType = (Breakdown_Type)cmbBreakdownType.SelectedItem;
            string selectedBreakdownTypeId = breakdownType.BrkdwnId;

            IQueryable<Breakdown_Type> breakdownTypeQuery = from t in Breakdowns.Breakdown_Types
                                                            where t.BrkdwnId == selectedBreakdownTypeId
                                                            select t;
            List<Breakdown_Type> selectedBreakdownId = breakdownTypeQuery.ToList();

            if (selectedBreakdownId != null && selectedBreakdownId.Count > 0)
            {
                BreakdownTypes = selectedBreakdownId.First();
                txtBreakdownId.Text = BreakdownTypes.BrkdwnId.ToString();
            }
            else
            {
                BreakdownTypes = null;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                Breakdown newBreakdown = new Breakdown();

                Breakdown_Type breakdownType = (Breakdown_Type)cmbBreakdownType.SelectedItem;
                newBreakdown.BrkdwnType = breakdownType.ToString();   //this is where the error occurs

                newBreakdown.MachineId = txtMachineId.Text.Trim();
                newBreakdown.MachineType = txtMachineType.Text.Trim();
                newBreakdown.ReportedDate = dtpDate.Value;
                newBreakdown.JobStatus = "I";

                Breakdowns.AddToBreakdowns(newBreakdown);
                int rowsAffected = Breakdowns.SaveChanges();
                if (rowsAffected > 0)
                {
                    MessageBox.Show(rowsAffected + " records added!", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured! " + ex.Message);
            }
        }
    }
}

I’m trying to save the data in the form back to the database, an error occurs when trying to cast the value selected from the Combobox. Even when I’ve casted it to the right type, it does not save the selected value! But this,

enter image description here

I’m clueless on what I’m doing wrong here? Can anyone please tell me how to correct this?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:17:28+00:00Added an answer on June 13, 2026 at 10:17 am
    newBreakdown.BrkdwnType = breakdownType.ToString();
    

    Here you are just calling .ToString() Method of your object, so it is returning the Type Name, which you are able to view in database table record, for getting the BrkDwnType Property value you should change statement to

    newBreakdown.BrkdwnType = breakdownType.BrkdwnType; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a new application using Entity Framework 4.3 database migrations. The migrations
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
I have been using Entity Framework 4.3 on an existing database and I have
I am using Entity Framework from .NET 3.5 I have two tables with 0-1
I have a WPF Datagrid populated with data from one SQL table using Entity
Using Entity Framework 4.3 in one of my data access classes I have generic
I am using Entity Framework Code First and have some Classes with a System.Net.Mail.MailAddress
I have a WinForms application which is using Entity Framework to query a database.
I am using Entity framework and have 1 field in database AddedDate that is
I am using entity framework to insert details into the database where I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.