c# - How to write OleDbCommand to get only distinct rows? -


i want have rows has distinct manufacturerpartnumber excel sheet.

so that, gave command text this:

cmdexcel.commandtext = "select name, distint [manufacturerpartnumber],price [" + sheetname + "] [manufacturerpartnumber] not null"; 

but this's not working, , if changed distinct [manufacturerpartnumber] manufacturerpartnumber, works. , returns duplicated rows don't want happen.

this's error got:

an unhandled exception of type 'system.data.oledb.oledbexception' occurred  additional information: syntax error (missing operator) in query expression 'distinct [manufacturerpartnumber]'. 

sample data

my excel sheet

name        manufacturerpartnumber      price pendrive    agbn514a                    5.4 harddisk    nkdnkhs5                    9.6 datacard    agbn514a                    6.3 

//here agbn514a appeared 2 times, that's in pendrive , datacard

expected output

name        manufacturerpartnumber      price pendrive    agbn514a                    5.4 harddisk    nkdnkhs5                    9.6 

//it should omit manufacturerpartnumbers

thanks

does tsql work?

i've ever seen distinct used before

select distinct name, [manufacturerpartnumber],price ... 

update

and i've noticed you're missing "c" distinct.

update 2:

try sql:

select name, [manufacturerpartnumber],price  (    select name, [manufacturerpartnumber],price ,       row_number() on (partition [manufacturerpartnumber] order     [manufacturerpartnumber]) row_number     test    ) rows row_number = 1 

update 3:

you trying select from test test table. you'll want substitute sheetname.

cmdexcel.commandtext = "select name, [manufacturerpartnumber],price ( select name, [manufacturerpartnumber],price , row_number() on (partition [manufacturerpartnumber] order [manufacturerpartnumber]) row_number  [" + sheetname + "]) rows row_number = 1" 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -