我已經按desc順序對一組記錄進行了排序,而不是在頂部獲得PK-10我正在獲得PK-9爲什麼會這樣,即使您刪除前綴並將其返回排序9。請建議在SQL Server中的溶液或C#排序唯一標識號
UniqueIdentificationNo
PK - 9
PK - 8
PK - 7
PK - 6
PK - 4
PK - 2
PK - 10
SELECT [UniqueIdentificationNo]
FROM [Product] order by [UniqueIdentificationNo] desc
C#代碼,int.parse返回錯誤,此代碼也返回PK - 9
var lastProduct = DbContext.Products.OrderByDescending(x => int.Parse(
(x.UniqueIdentificationNo ?? string.Empty).Replace(prefix, string.Empty).Trim())).FirstOrDefault();
看起來你的變量是字符串。將'UniqueIdentificationNo'轉換爲整數 –
UniqueIdentificationNo的數據類型是什麼? – Ajay2707
Its varchar(100) –