如何编写OleDbCommand来获取不同的行?

我只想要从我的Excel表中具有不同的ManufacturerPartNumber的行。

所以,我给了我这样的命令文本:

cmdExcel.CommandText = "SELECT Name, DISTINT [ManufacturerPartNumber],Price From [" + SheetName + "] WHERE [ManufacturerPartNumber] IS NOT NULL"; 

但是这不起作用,如果我将DISTINCT [ManufacturerPartNumber]更改为ManufacturerPartNumber ,它就可以工作。 它返回我不想发生的重复行。

这是我得到的错误:

 An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred Additional information: Syntax error (missing operator) in query expression 'DISTINCT [ManufacturerPartNumber]'. 

样本数据

我的Excel工作表

 Name ManufacturerPartNumber Price PenDrive AGBN514A 5.4 HardDisk NKDNKHS5 9.6 DataCard AGBN514A 6.3 

//这里AGBN514A出现了两次,就是PenDrive和DataCard

预期产出

 Name ManufacturerPartNumber Price PenDrive AGBN514A 5.4 HardDisk NKDNKHS5 9.6 

//它应该省略ManufacturerPartNumbers

谢谢

Tsql是否工作?

我以前只见过不同的用法

 SELECT DISTINCT Name, [ManufacturerPartNumber],Price From ... 

UPDATE

而且我刚刚注意到你从DISTINCT中错过了一个“c”。

更新2:

试试这个SQL:

 select Name, [ManufacturerPartNumber],Price from ( select Name, [ManufacturerPartNumber],Price , row_number() over (partition by [ManufacturerPartNumber] order by [ManufacturerPartNumber]) as row_number from test ) as rows where row_number = 1 

更新3:

你正试图from test我的testing表中selecttesting。 您将需要replace您的图纸名称。

 cmdExcel.CommandText = "select Name, [ManufacturerPartNumber],Price from ( select Name, [ManufacturerPartNumber],Price , row_number() over (partition by [ManufacturerPartNumber] order by [ManufacturerPartNumber]) as row_number from [" + SheetName + "]) as rows where row_number = 1"