简体   繁体   English

通过降vb.net对二维数组进行排序

[英]sort two dimensional array by descending vb.net

Please could you help me sort this by 2nd column descending? 请您帮我按第二列的降序排列吗?

Dim ds As New DataSet()
conn.Open()

techSpeciality = LB_techFaultType.Text
techZone = LB_TechZone.Text

Dim strSQL As String = "SELECT Tech_ID, Last_Zone FROM Technician_List WHERE Availability=TRUE AND Speciality='" & techSpeciality & "' AND Last_Zone='" & techZone & "'"
Dim da As New OleDbDataAdapter(strSQL, conn)

da.Fill(ds)
'2D array
Dim values(ds.Tables(0).Rows.Count - 1, 2) As Integer

'for loop between 0 and all available technicians
For value As Integer = 0 To ds.Tables(0).Rows.Count - 1
'Tech_ID column
  values(value, 0) = ds.Tables(0).Rows(value).Item(0).value()
  'Zone column, converts negative value to a positive and minus' the selected techZone
  Math.Abs(values(value, 1) = techZone - ds.Tables(0).Rows(value).Item(1).value())
Next

Modify this line: 修改此行:

Dim strSQL As String = "SELECT Tech_ID, Last_Zone" & _
                      " FROM Technician_List WHERE" & _
                      " Availability=TRUE AND Speciality='" & techSpeciality & _
                      "' AND Last_Zone='" & techZone & _
                      "' ORDER BY Last_Zone DESC"

For more information on the ORDER BY keywords: http://www.w3schools.com/sql/sql_orderby.asp 有关ORDER BY关键字的更多信息: http : //www.w3schools.com/sql/sql_orderby.asp

另一种选择是执行ORDER BY 2 DESC ,而不是直接指定列名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM