By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Exactly like SQL Server table order

P: n/a
Hi
i have a code to retrieve table structures of SQL Server
database.
It gives all the table names in particular databse with
the column names and datatypes also.
But the output displays not in the exact order of what i
am designing in SQL Server database,mainly coulmnnames are
not in order.
I want to displayed output exactly like what i was
designed in SQL Server table.
How can i displyed like that is there any solution?
Please give me reply.
The code is:

<%
'Set Conn = Server.CreateObject("ADODB.Connection")
Set cn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={SQL
Server};SERVER=SERVER;UID=sa;PWD=thanks;DATABASE=p arameter"
cn.open DSNtest
Set sysObjects = cn.Execute("SELECT * FROM sysObjects
WHERE xtype = 'U' ORDER BY name")

If sysObjects.eof Then
Response.write("No records returned")
End If

do until sysObjects.eof
'if not sysObjects("name")="dtproperties" then

Response.write("<table width='100%' border='1'>")
Response.write("<tr><td colspan='3'><b>Table
Name:" & sysObjects("name") & "</b></td></tr>")
Response.write("<tr><td><b>Field
Name</b></td><td><b>Data Type</b></td><td><b>Data Type
Length</b></td></tr>")
Set sysColumns = cn.Execute("SELECT A.name
As 'ColumnName', B.name As 'DataType', A.length
As 'DataTypeLength' FROM sysColumns As A INNER JOIN
sysTypes As B On (A.xtype = B.xtype) WHERE id = " &
sysObjects("id") & " ORDER BY A.name")

if sysColumns.eof Then
Response.write("<tr><td><i>No columns
found for " & sysObjects("name") & " table.</i></td></tr>")
end if

do until sysColumns.eof
Response.write("<tr><td>" & sysColumns
("ColumnName") & "</td><td>" & sysColumns("DataType")
& "</td><td>" & sysColumns("DataTypeLength")
& "</td></tr>")
sysColumns.movenext
loop
Response.write("</table>")
Response.write("<br><br>")
sysObjects.movenext
'end if
loop

cn.Close
Set cn = Nothing
%>

Thanks
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.