2012-11-22 172 views
0

請你能幫我按第二列降序排序嗎?按降序排列二維數組vb.net

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 

回答

1

修改這一行:

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" 

有關ORDER更多信息通過關鍵詞: http://www.w3schools.com/sql/sql_orderby.asp

0

另一種選擇是做ORDER BY 2 DESC,而不是直接指定的列名。