【发布时间】:2014-02-08 11:30:24
【问题描述】:
我用来显示库存表的代码如下。
con = conn.getConnected();
datadap.SelectCommand = new SqlCommand("SELECT Inventory.inv_ID AS ID, ItemType.it_type AS Type, Inventory.inv_qty AS [Qty],Inventory.inv_part_no AS [Part No], CONVERT(DECIMAL(10,2),Inventory.inv_whole_price) AS [Discount Price], CONVERT(DECIMAL(10,2),Inventory.inv_retail_price) AS [Selling Price], Inventory.inv_profit_percent AS [Percent] FROM Inventory INNER JOIN Country ON Inventory.count_ID = Country.count_ID INNER JOIN Class ON Inventory.class_ID = Class.class_ID INNER JOIN Dealer ON Inventory.deal_ID = Dealer.deal_ID INNER JOIN ItemType ON Inventory.it_ID = ItemType.it_ID", con);
dataset.Clear();
datadap.Fill(dataset);
dgInventory.DataSource = dataset.Tables[0];
结果集“Inventory”是
Inv_ID Type Qty Code Cost Sell Percent
3 Spockets Rear 1 1000 100.00 150.00 33.33
4 Seat Cover 1 1000 10.00 12.00 16.67
5 Brake Cable 1 5000 20.00 24.00 2
6 Seat Cover 1 4400 400.00 411.00 1
8 Spockets Rear 1 1503 1522.00 1252.00 15
9 Seat Cover 1 1522 152.00 180.00 12
10 Seat Cover 1 1522 152.00 180.00 12
11 Seat Cover 1 1522 152.00 180.00 12
12 Lights 1 5623 123.00 160.00 10
13 Brake Shoe 1 90.00 100.00 10
14 Brake Shoe 1 90.00 100.00 10
15 Sprockets Front 1 100 2000.00 2200.00 9.0
16 Spockets Rear 3 1001 615.00 800.00 23.125
InventoryMake 表以 Inventory ID 作为外键。 InventoryMake 表看起来像
ID Model_ID Inv_ID
1 2 15
7 3 15
8 5 14
9 4 14
我需要做的是在 Inventory 表的一行中显示外键 Inv_ID 对应的 Model_ID,如图所示下面。
Inv_ID Type Model_ID Qty Code Cost Sell Percent
3 Spockets Rear 1 1000 100.00 150.00 33.33
4 Seat Cover 1 1000 10.00 12.00 16.67
5 Brake Cable 1 5000 20.00 24.00 2
6 Seat Cover 1 4400 400.00 411.00 1
8 Spockets Rear 1 1503 1522.00 1252.00 15
9 Seat Cover 1 1522 152.00 180.00 12
10 Seat Cover 1 1522 152.00 180.00 12
11 Seat Cover 1 1522 152.00 180.00 12
12 Lights 1 5623 123.00 160.00 10
13 Brake Shoe 1 90.00 100.00 10
14 Brake Shoe 5,4 1 90.00 100.00 10
15 Sprockets Front 2,3 1 100 2000.00 2200.00 9.0
16 Sprockets Rear 3 1001 615.00 800.00 23.125
我需要你的帮助来弄清楚如何在一行中显示多条记录,如上表所示。谢谢。 PS:我使用的是 C# 和 MSSQL 2008
【问题讨论】:
标签: c# sql datagridview multiple-tables records