I make many to many relationship in erd diagram in sql server 2005 between ca and driver as following
car table
driver table
car_driver table.
I need to make fleet management program. When I make forms in windows form are i make car form driver form car_driver form When i insert data are creating three forms each form insert to related tables
car table car form
driver table driver form
car_driver table car_driver form

please help me

3 Years
Discussion Span
Last Post by MarkAMalo

Well, you can do one of the following:
1) Create a SQL Stored Proc to handle this for you
2) Use Linq (or nHibernate) to handle this for you
3) Do it yourself

If you do it yourself, you will need to do something like (this is Psuedocode):
INSERT INTO CAR (Make, Model, Year) VALUES ('Pontiac', 'Firebird', '1973')
and using SQLCommand you can return the Primary Key (probably CarId) from your Car table, then:
INSERT INTO DRIVER (Name, LicenseNo) VALUES ('Dr Who', 'baDWolf')
and again, use the SQLCommand ExecuteNonQuery to return the DriverId
and finally:
INSERT INTO CarToDriver(CarId, DriverId) VALUES (CarId, DriverId)

A storedproc can do this for you too, I can help you with that if that is the way you want to go. I, however, suggest nHibernate or Linq as that relationship can be handled without any coding from you.

Hope this helps,
Mark A. Malo

Edited by MarkAMalo: misspelled nHibernate

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.