RP Nainwal
RP Nainwal

Reputation: 305

asp.net query with insertion of values in a table

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.

Upvotes: 3

Views: 312

Answers (1)

Rajeshkumar Kandhasamy
Rajeshkumar Kandhasamy

Reputation: 6461

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...

Upvotes: 3

Related Questions