在Gridview中显示Sql表记录

时间:2018-04-27 06:22:28

标签: c# sql-server

this表中,我从gridview动态行输入多个记录。

现在我想在不同的网页gridview上显示these条记录。请建议我在SQL查询中应该放什么。我正在使用C#SQL Server。

1 个答案:

答案 0 :(得分:1)

你的照片

--Test Data
CREATE TABLE YourTable
    ([col] int, [col2] int, [col3] int, [col4] varchar(13), [col5] varchar(6), [col6] varchar(6), [col7] varchar(10), [col8] varchar(7), [col9] varchar(10))
;

INSERT INTO YourTable
    ([col], [col2], [col3], [col4], [col5], [col6], [col7], [col8], [col9])
VALUES
    (4, 4, 4, 'Home Threatre', 'Area', 'Deepak', 'Gram', 'CCAA2', 'Inches'),
    (5, 5, 4, 'Home Threatre', 'Area', 'Rahul', 'Inches', NULL, '0'),
    (6, 6, 5, 'Home Threatre', 'length', 'a1', 'Gram', 'ann2', 'IClogram'),
    (7, 7, 5, 'Home Threatre', 'length', 'bl', 'Centimeter', 'bnn2', 'Meter'),
    (8, 8, 6, 'Home Threatre', 'Width', 'zzl', 'Centimeter', 'z222', 'Centimeter'),
    (9, 9, 6, 'Home Threatre', 'Width', ')71', 'Milimeter', 'y222', 'Milimeter'),
    (10, 10, 6, 'Home Threatre', 'Width', 'x211', 'Centimeter', NULL, '0'),
    (11, 11, 3, '2PinSwitch', 'A3pin3', 'sddsf', 'Meter', 'dsfsctf', 'Milimeter'),
    (12, 12, 3, '2PinSwitch', 'A3pin3', 'dddd', 'Centimeter', NULL, '0')
;

--Query Script
select [col], [col2], [col3], [col4], 
  case when rank = 1 then
    [col5]
  else
    ''
  end as [col5]
  , [col6], [col7], [col8], [col9]
from (
  select 
    *
    ,ROW_NUMBER() OVER(PARTITION BY col5 ORDER BY col5 ASC) rank
  from YourTable
) TempTable

结果:

DEMO LINK