HOW To insert INTO tble a and select table b with asp.net
this my table
table a
id_pk
name varchar(30)
office varchar(30)
date
table b
id_sek int Pk
sektor1 varchar(23)
sektor2 varchar(23)
sarana varchar(33)
id_pk int
HOW To insert INTO tble a and select table b with asp.net
this my table
table a
id_pk
name varchar(30)
office varchar(30)
date
table b
id_sek int Pk
sektor1 varchar(23)
sektor2 varchar(23)
sarana varchar(33)
id_pk int
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suraj SahooPosted Feb 15, 2015, 8:09 AM
I donot know if I clearly understand your query here, but as I get please follow the below statements/query:-
INSERT INTO table_A
VALUES(NAME,OFFICE,DATE)
Make sure to make the Primary key an identity column, that is make it auto incremented. The values will have the original values you want to insert i.e. Name, office & date.
As I see in the table_b you have the primary key of table a as the Foreign key, which indicates that there would be a clear relationship between the tables, may it be one to many or one to one. So after insertion you want to select the data from the table_b where the id_pk matches a specific id.
To achieve the above requirement(if I am correct to understand), you need to save the id of the table_a record that is associated with the table_b record being saved. Like for example, there is a record in table_a with Name : Suraj
and His address you are saving in table_b so for that you need to fetch the id_pk of the record with name Suraj and then save that into table_b id_pk.
Then to select the record, you need to write the below query:
SELECT * FROM table_b as test
WHERE test.id_pk == 'ID'
I hope you understand what I tried to explain.
Please post back your queries if any.
Accept if helps you anyway.
Thanks