Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am beginner in coding and i am using three tables named tour package.tour description,inclusion and these three are connected by primary and foreign key relationship.below is my tables and its columns

Tour Package
id
heading
description
image

tour description
id
place
description
image1

Inclusion
id
inclusion

tour description's id and inclusion's id are the foreign key and they point to tour package's id which is the primary key.
Can anyone tell me how to insert as well as retrieve data into these three tables using c# and sql query.please help me.Thank u in advance.god bless you
Posted
Updated 3-Aug-14 5:40am
v3

1 solution

For retrieval, use SELECT and JOIN
1. sql_join[^]
2. Visual Representation of SQL Joins[^]
For insertion, use INSERT. But you have to make sure that the new data is first inserted into the primary table with a new id, before it can be inserted into the foreign tables with the same new id.
3. sql_insert[^]
Lastly, you should avoid using table name or field name that has space in between, it is annoying, as you have to bracket it, like this: [Tour Package]
 
Share this answer
 
v2
Comments
faizel s 4-Aug-14 3:09am    
Thanks for trying to help me.First i tried to insert record onto the primary table but i am getting error 'Cannot insert the value NULL into column 'id', table 'isanchari.dbo.TOURPACKAGE'; column does not allow nulls. INSERT fails. The statement has been terminated.'.I think we have to make primary key column also a identity column.Can you tell me query for altering my primary key column and make it a identity column
Peter Leow 4-Aug-14 3:30am    
Check this out: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/04d69ee6-d4f5-4f8f-a115-d89f7bcbc032/how-to-alter-column-to-identity11
But do it with care as you have existing data.

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