在表中插入值的Asp.net查询

本文关键字:Asp net 查询 插入 | 更新日期: 2023-09-27 18:18:44

假设数据库中有三个表:

  1. tbl_companymaster (company_id (PK), company_name)
  2. tbl_papermaster (paper_id (PK), paper_name,利率)
  3. tbl_rate (rate_id (PK), company_id(颗),paper_id(颗),利率)

我们必须使用c#语言在asp.net中点击按钮时触发insert查询。

我们必须插入company_id (from tbl_companymaster),paper_id(from tbl_papermaster),rate(from tbl_papermaster)到tbl_rate示例:

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

请帮我找合适的代码。这段代码给我带来了很大的麻烦。

在表中插入值的Asp.net查询

首先,您应该了解表之间的外键和主键关系。以及SQL Join。然后,只有u可以执行这么多的插入和数据绑定来查看。

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

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

For yours每个公司必须有唯一标识符。根据company_id (from tbl_companymaster),设置foreignkey for paper_id(from tbl_papermaster), foreign Key for rate(from tbl_papermaster)为tbl_rate。根据Key Relationships进行编码操作

先清除关系,然后再做。会好起来的。