6 Replies - 354 Views - Last Post: 26 April 2019 - 04:38 AM Rate Topic: -----

#1 Savageoncabbage   User is offline

  • New D.I.C Head

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

Need help with my application

Posted 25 April 2019 - 07:05 PM

I have created an application with a database attached but I cannot find the next steps. Can someone help me? I am supposed to have it where if someone checks the type of car it will look up the price through the database linked and show the price of the car.

using System;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;

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

        private void loadgrid()
        {
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
            con.Open();
        }

        private void CarPrice_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'honestRalphsUsedCarsDataSet.tblCars' table. You can move, or remove it, as needed.
            this.tblCarsTableAdapter.Fill(this.honestRalphsUsedCarsDataSet.tblCars);
        }
        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");
                if (this.Text == "210Chevrolet")
                    MessageBox.Show("price of this car is 8,000");
                if (this.Text == "2005Toyota")
                    MessageBox.Show("price of this car is 12,000");
                if (this.Text == "2010BMW")
                    MessageBox.Show("price of this car is 22,500");
                if (this.Text == "2007Fod")
                    MessageBox.Show("price of this car is 20,000");
                if (this.Text == "2009Chrysler")
                    MessageBox.Show("price of this car is 15,500");
                if (this.Text == "2007Cadillac")
                    MessageBox.Show("price of this car is 27,600");
                if (this.Text == "2005Ford")
                    MessageBox.Show("price of this car is 8,500");
                if (this.Text == "2011Cadillac")
                    MessageBox.Show("price of this car is 12,400");
                if (this.Text == "2007Chevrolet")
                    MessageBox.Show("price of this car is 24,500");
            }
        }
//if the item is not selected the below message is displayed
            //else
                //Response.Write("You unchecked " + CheckBoxList1.SelectedItem.Text);

    }
}



I have also attached a zip of the folder.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Need help with my application

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15111
  • View blog
  • Posts: 60,452
  • Joined: 12-June 08

Re: Need help with my application

Posted 25 April 2019 - 07:40 PM

What is your question?
Was This Post Helpful? 0
  • +
  • -

#3 Savageoncabbage   User is offline

  • New D.I.C Head

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

Re: Need help with my application

Posted 25 April 2019 - 07:55 PM

So I was able to connect the database but I dont know how to code where when the user chooses a car from the checkboxlist for it to populate a price by checking the database and returning just the price for that car to the listbox.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15111
  • View blog
  • Posts: 60,452
  • Joined: 12-June 08

Re: Need help with my application

Posted 25 April 2019 - 08:37 PM

Okay.. so you would use a data adapter to fill a dataset based off a SQL query you wrote.

ex:
https://www.dreaminc...-adapter-setup/
https://www.dreaminc...-command-setup/
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6798
  • View blog
  • Posts: 28,097
  • Joined: 12-December 12

Re: Need help with my application

Posted 25 April 2019 - 11:56 PM

If you are using a TableAdapter then, as I recall, you can use the DataSet Designer to create a new query that would return a price based on the car name/code.

Create and configure TableAdapters
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6968
  • View blog
  • Posts: 23,678
  • Joined: 05-May 12

Re: Need help with my application

Posted 26 April 2019 - 04:10 AM

As an aside, there seems to be something wrong with your UI design. Why would choosing items in a check listbox put prices into another listbox. So if the check listbox had items A, B, C, and D, then I checked D and A, in that order, the other listbox will have the prices of D and A in that order. So if the user walks away and comes back later, how will he know that the first price is for D and the second is for A when all he can see is that A and D are checked.
Was This Post Helpful? 1
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6968
  • View blog
  • Posts: 23,678
  • Joined: 05-May 12

Re: Need help with my application

Posted 26 April 2019 - 04:38 AM

Even more interesting now that I see your code on a bigger screen. It looks like you are using some kind of grid view, assuming that loadgrid() was appropriately named. If that is true, then why even do the lookup at the time the user selects an item? Why not simply populate the grid with the car and the price side by side? Is this somekind of car dealership where decide to make a purchase, suddenly the sticker price is not the price and you need to wait for the dealer to go to talk to his manager and his finance guy before giving you a price?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1