Visual Basic - Order By from Database - TechRepublic
Question
January 26, 2010 at 04:27 AM
martinbullock15

Visual Basic – Order By from Database

by martinbullock15 . Updated 16 years, 5 months ago

Hi

I have created a list box which is populated from a table in a database.

I was wondering if there was a way to order the list by the primary number in the same table?

This is the code which lists the values:

varSQLCmd = “SELECT * FROM Dpt”
varDptRecSet.Open varSQLCmd, varDptConn, adOpenStatic

DptCount = 0
If varDptRecSet.RecordCount > 0 Then
varDptRecSet.MoveFirst
Do While Not varDptRecSet.EOF
lstDpt.AddItem varDptRecSet.Fields(“Code”) & ” – ” & varDptRecSet.Fields(“Dpt”)
DptCount = DptCount + 1
varDptRecSet.MoveNext
Loop
End If

The field in the table which contains the primary ID is named “ID” this is the field i would like the list to be ordered by.

Thanks in advance

Martin

This discussion is locked

All Comments