1

My first post here (i'm italian).

I have a question about the order of a cicle of For/Next... at moment use this code for retrieve automatically the columns of a DB access (ASP + DB ACCESS). I would like to know if is possible to order alphabetically this cicle...

<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("miodb.mdb")
Set objRs = Server.CreateObject("ADODB.Recordset")
strSQL="SELECT * FROM articoli"
objRs.Open strSQL, objConn,3,3

For each field in objRs.Fields
%>

<div class="form-group">
    <div class="input-group">
      <div class="input-group-addon"><b><%=field.name%></b></div>
      <input type="<%=field.name%>" class="form-control" id="exampleInputAmount" name="<%=field.name%>">
      <div class="input-group-addon">mq</div>
    </div>
</div>


<% Next %>
YowE3K
  • 23,852
  • 7
  • 26
  • 40
Aux998
  • 11
  • 1
  • Just specify the fields in any order you want in the `SELECT` query rather then using `*`, so `SELECT col1, col2, col3 ... ` and so on. – user692942 Apr 26 '17 at 14:22
  • Might be useful, but some syntax may not be relevant to a MSAccess Query - [SQL Listing all column names alphabetically](http://stackoverflow.com/a/4075845/692942). – user692942 Apr 26 '17 at 14:29
  • 4
    Possible duplicate of [SQL Listing all column names alphabetically](http://stackoverflow.com/questions/4075800/sql-listing-all-column-names-alphabetically) – user692942 Apr 26 '17 at 14:31

1 Answers1

0

By your question you seem to want to order column names in the table, although you do a "select from"

Instead you could use the Information_schema

select * from information_schema.columns where table_name='articoli' order by column_name

This will give you all the columns in that table that you can then cycle through.

If I misunderstood and you want to order the actual result from the select statement then you need a column to order on and just add that to the select statement.

select * from articoli order by specifik_column_name
Sourcery
  • 641
  • 1
  • 5
  • 15