3

suppose we have three tables in the Database:

  1. tbl_companymaster(company_id(PK),company_name)
  2. tbl_papermaster(paper_id(PK),paper_name,rate)
  3. tbl_rate(rate_id(PK),company_id(FK ),paper_id(FK),rate)

we have to fire a query of insert on the clicking of a button in asp.net with c# language.

we have to insert the company_id (from tbl_companymaster),paper_id(from tbl_papermaster),rate(sfrom tbl_papermaster) into tbl_rate Example:

tbl_companymaster:

company_id     company_name
-----------------------------------
 1            lalit and company
-------------------------------------
 2            deepesah and co.
-----------------------------------
 3                 RP & Co.
-------------------------------------

tbl_papermaster:

paper_id          paper_name          rate
-------------------------------------------------
  1                 plain             400
------------------------------------------------
  2                 carbon            300
-------------------------------------------------
  3                 butter            500

tbl_rate:

rate-id        company_id          paper_id               rate
---------------------------------------------------------------

1                 1                   1                 400
--------------------------------------------------------------------

2                 1                   2                 300
-----------------------------------------------------------------------
3                 1                   3                 500
------------------------------------------------------------------------
4                 2                   1                 400
-----------------------------------------------------------------------
5                 2                   2                 300
---------------------------------------------------------------------
6                 2                   3                 500
------------------------------------------------------------------------

Please help me with the suitable code.I m in a great trouble with this code.

Thanks in advance.

7
  • 2
    You should get a good book on databases. Or hire someone to do this. Commented Dec 25, 2011 at 17:54
  • 1
    What have you tried so far? This is a help/Q&A site, not "write this for me". Commented Dec 25, 2011 at 18:16
  • Use cross join companymaster and papermaster Commented Dec 25, 2011 at 18:30
  • Is this school homework? Commented Dec 26, 2011 at 5:38
  • you haven't provided much info. Do you have stored procedures or you want to use Linq to SQL or Linq to Entity Commented Dec 26, 2011 at 11:36

1 Answer 1

3

First you should aware of Forign key and primary key relationships between the table.As well as the SQL Join. Then only u can perform this much of Insertions and DataBindings to view.

http://www.codeproject.com/KB/database/TableReader.aspx

http://msdn.microsoft.com/en-us/library/aa213227(v=sql.80).aspx

For yours Each company must have uniquidentifier.Based on the company_id (from tbl_companymaster),set Forign Key for paper_id(from tbl_papermaster),set Forign key for rate(from tbl_papermaster) into tbl_rate.Perform the coding operation based on the Key Relationships.

First clear with Relationship then do it. It will be Better.

Hope this may helpful...

Sign up to request clarification or add additional context in comments.

2 Comments

Please read this: meta.stackexchange.com/questions/5234/…. Since it seems you have not yet discovered how to accept answers.
thanks for ur answer.i m writing the exact query in sql but i have to implement it with c# in asp.net

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.