Click here to Skip to main content
15,608,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir

now if i have table1 with following data

CarID CarName
100 BMW
200 Lancer
300 JEEP

and i have another table2

PriceID CarID Price Date
auto inc
now i want a datagridview with following shape (CarID & CarName will not be entered it will filled from table1 by somehow)

CarID CarName PriceID Price Date

now i want to be able to enter new data in the datagrid
so for example

CarID CarName PriceID Price Date
100 BMW autogen 500K$ 1/6/2011
200 Lancer " 100k$ 2/6/2011
300 Jeep " 200K$ 10/6/2011
100 BMW autogen 510K$ 1/7/2011
200 Lancer " 130k$ 20/7/2011
300 Jeep " 240K$ 30/7/2011

so after saving tabel should no change at all but table2 should be updated

PriceID CarID Price Date
autogen 100 500K$ 1/6/2011
" 200 100k$ 2/6/2011
" 300 200K$ 10/6/2011
" 100 510K$ 1/7/2011
" 200 130k$ 20/7/2011
" 300 240K$ 30/7/2011

so how can i made that??

i don't want a complete code i want just some tips
i don't know how to make the datagridview read from two tables but update only one of them
i know how to make the datagrid read from two tables using select join
but when it update how to make it update one of them
Updated 20-Jul-11 2:41am

1 solution

Personally, I think that your database tables don't really do what you are trying to do. I notice that every BMW (or Jeep) will have the same Car ID, and I am sure this is not what you meant. I would structure my tables something like this:

CarMake<br />
<br />
CarMakeID int(AI)<br />
CarMake varchar<br />
<br />
Car<br />
<br />
CarID int(AI)<br />
CarMakeID int(Foreign key to CarMakeID)<br />
Price decimal<br />
Date datetime

Then i would create a class for each type CarMake and Car, something along these lines

class CarMake
        int carID;
        string carMake;
    class Car
        int carID;
        int carMakeID;
        decimal Price;
        DateTime date;

        public void InsertCar()
           "INSERT INTO Cars(carMakeID, Price, Date) VALUES etc"


That way when you add a new vehicle you can just call the Insert method.

Hope this helps

Then when you add
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