Can someone help with my project to see what I am doing wrong?

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 977 Views - Last Post: 24 April 2019 - 05:47 PM Rate Topic: -----

#1 Savageoncabbage   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-April 19

Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:38 AM

This is what was asked of me for C#.
Create an application in which all of the cars in a database are displayed in a checked list box. When the user makes a selection, the carís price is displayed, as shown in figure below. Use the HonestRalphsUsedCars database in your downloadable student files. Save the project as CarPriceFinder.

I know I am close but I cannot see where I have issues.

using System;
using System.Windows.Forms;
using System.Linq;
using System.Collections.Generic;

namespace CarPriceFinder
{
    public partial class CarPrice : Form //creating a carPrice class
    {
        public CarPrice()//carPrice empty constuctor calling
        {
            InitializeComponent();//Initializing components
        }

        private void CarPrice_Load(object sender, EventArgs e)
        {
            var items = checkedListBox1.Items;//creating an object called Items
            items.Add("2006 Ford");//adding components through object
            items.Add("2010 Chevrolet");
            items.Add("2005 Toyota");
            items.Add("2010 BMW");
            items.Add("2007 Ford");
            items.Add("2009 Chrysler");
            items.Add("2007 Cadillac");
            items.Add("2005 Ford");
            items.Add("2011 Cadillac");
            items.Add("2007 Chevrolet");
        }
        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Get the selected index of the item.
            int selected = checkedListBox1.SelectedIndex;
            if (selected != -1)
            //checking whether the item is selected or not and finding its name
            {
                this.Text = checkedListBox1.Items[selected].ToString();
                Response.Write("You checked " + CheckBoxList1.SelectedItem.Text);
                if (this.Text == "2006Ford")
                    //writing the code for displaying price when the item is clicked   
                    MessageBox.Show("price of this car is $21,500.00");
                if (this.Text == "2010Chevrolet")
                    MessageBox.Show("price of this car is $8,000.00");
                if (this.Text == "2005Toyota")
                    MessageBox.Show("price of this car is $12,000.00");
                if (this.Text == "2010BMW")
                    MessageBox.Show("price of this car is $22,500.00");
                if (this.Text == "2007Ford")
                    MessageBox.Show("price of this car is $20,000.00");
                if (this.Text == "2009Chrysler")
                    MessageBox.Show("price of this car is $15,500.00");
                if (this.Text == "2007Cadillac")
                    MessageBox.Show("price of this car is $27,600.00");
                if (this.Text == "2005Ford")
                    MessageBox.Show("price of this car is $8,500.00");
                if (this.Text == "2011Cadillac")
                    MessageBox.Show("price of this car is $12,400.00");
                if (this.Text == "2007Chevrolet")
                    MessageBox.Show("price of this car is $24,500.00");
            }
            //if the item is not selected the below message is displayed
            else
                Response.Write("You unchecked " + CheckBoxList1.SelectedItem.Text);
        }
    }
}

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Can someone help with my project to see what I am doing wrong?

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6881
  • View blog
  • Posts: 23,344
  • Joined: 05-May 12

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:41 AM

If the database contains the prices, why not pull the prices from there as well instead of hard coding the prices into the code?
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2836
  • View blog
  • Posts: 11,132
  • Joined: 03-December 12

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:43 AM

View PostSavageoncabbage, on 24 April 2019 - 12:38 PM, said:

I know I am close but I cannot see where I have issues.


And what are those issues?

View PostSkydiver, on 24 April 2019 - 12:41 PM, said:

If the database contains the prices, why not pull the prices from there as well instead of hard coding the prices into the code?


Among all the other data.

OP you need classes and to separate out the UI from the logic.
Was This Post Helpful? 1
  • +
  • -

#4 Savageoncabbage   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-April 19

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:46 AM

View PostSkydiver, on 24 April 2019 - 10:41 AM, said:

If the database contains the prices, why not pull the prices from there as well instead of hard coding the prices into the code?

I have tried to connect the database and have received an error every time I tried. It stated 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. I tried installing AccessDatabaseEngine_X64.exe as well but it would not work.

So it runs and populates but when I check an item it does not display anything. I also have errors with line 37 and 62
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2836
  • View blog
  • Posts: 11,132
  • Joined: 03-December 12

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:46 AM

https://docs.microso...ms?view=vs-2019
Was This Post Helpful? 0
  • +
  • -

#6 Savageoncabbage   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-April 19

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:50 AM

Those are the exact steps I am using and still getting the error when I am on the add connection page.

This post has been edited by Skydiver: 24 April 2019 - 02:49 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#7 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2836
  • View blog
  • Posts: 11,132
  • Joined: 03-December 12

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:51 AM

Do you have access installed where you can query the database currently?
Was This Post Helpful? 0
  • +
  • -

#8 Savageoncabbage   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-April 19

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:53 AM

Yes I have access installed and can even open the accdb file. It shows all the information but when I try to link it I always get that error.

This post has been edited by Skydiver: 24 April 2019 - 02:49 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#9 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2836
  • View blog
  • Posts: 11,132
  • Joined: 03-December 12

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:54 AM

https://docs.microso...ns?view=vs-2019
Was This Post Helpful? 0
  • +
  • -

#10 Savageoncabbage   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-April 19

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 10:57 AM

That would be adding a SQL and I need to add a accdb since that is the file I have. I don't have a SQL server connection to add.

This post has been edited by Skydiver: 24 April 2019 - 02:48 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#11 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2836
  • View blog
  • Posts: 11,132
  • Joined: 03-December 12

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 11:29 AM

You can also connect to an Access instance, but okay.

So the root of the issue to get corrected first, is the ability to connect to the Access file. before that, you are spinning your wheels as that is part of the assignment.

When you test the connection, what does it say?

https://social.msdn....etdataproviders
Was This Post Helpful? 0
  • +
  • -

#12 Savageoncabbage   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-April 19

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 12:04 PM

Ok so I have installed the AccessDatabaseEngine_X64 and when I test the connection, that is when I get the error I stated above.
'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine'.

This post has been edited by Skydiver: 24 April 2019 - 02:48 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#13 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2836
  • View blog
  • Posts: 11,132
  • Joined: 03-December 12

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 12:10 PM

https://stackoverflo...ot-registered-o
Was This Post Helpful? 0
  • +
  • -

#14 Savageoncabbage   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-April 19

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 12:13 PM

https://www.microsof...s.aspx?id=23734 "The download is no longer available."

This post has been edited by Skydiver: 24 April 2019 - 02:47 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#15 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14995
  • View blog
  • Posts: 59,882
  • Joined: 12-June 08

Re: Can someone help with my project to see what I am doing wrong?

Posted 24 April 2019 - 12:23 PM

You need the 2010 Access redistirbute.

https://www.microsof...s.aspx?id=13255
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2