SQL,XML,XSL,ASP,really,simple,grabbing,column
Quick Search for:  in language:    
SQL,XML,XSL,ASP,really,simple,grabbing,column
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 132,008 lines
 Jobs: 161 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript
List Records
By Edito P. Aspra Jr. on 8/26


DSN Less Connection to SQL Server Database
By alpesh shah on 8/26


Click here to see a screenshot of this code!Database Driven Select Menu w/ default select
By Jayson Starkey on 8/26

(Screen Shot)

A Simple guestbook in ASP
By Matthew Meadows on 8/25


Simple GuestBook or Feedback Page Requiring No Database Implementation
By Ken Alabi on 8/25


if i remember, this is a M. Harris code sample
By ask on 8/24


MTS Registration Script
By Igor Krupitsky on 8/23


Click here to see a screenshot of this code!Creating Windows Users with ASP and ADSI
By jamespwalters on 8/23

(Screen Shot)

News Poster (Advanced)
By Martin Kilbryde on 8/22


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Completely Reusable SQL Server/XML Generator !

Print
Email
 
VB icon
Submitted on: 2/21/2001 4:38:35 PM
By: Brandon McPherson 
Level: Intermediate
User Rating: By 5 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 7328 times.
 

(About the author)
 
     This is a really simple way of grabbing the column details for all the user tables in a SQL Server database, and converting those details to XML. If you wanted to get a little creative, you could re-use this with XSL to create SQL and ASP templates for your apps.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: Completely Reusable SQL Server/X
    '     ML Generator !
    ' Description:This is a really simple wa
    '     y of grabbing the column details for all
    '     the user tables in a SQL Server database
    '     , and converting those details to XML. I
    '     f you wanted to get a little creative, y
    '     ou could re-use this with XSL to create 
    '     SQL and ASP templates for your apps.
    ' By: Brandon McPherson
    '
    ' Inputs:The only real 'condition' is th
    '     at you should have a default database se
    '     t up in your connection.
    '
    ' Returns:XML data outlining the column 
    '     information for the tables in a database
    '     .
    '
    ' Assumes:I know this works in SQL Serve
    '     r 2000 and version 7.0, but I won't guar
    '     antee anything before that (I don't have
    '     copies of the system tables to check).
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.6504/lngWId.4/qx/vb/scripts/ShowCode.
    '     htm    'for details.    '**************************************
    
    <%
    Set Cnn1 = Server.CreateObject("ADODB.Connection")
    Set adoCmd = Server.CreateObject("ADODB.Command")
    Dim sXML
    ' Set the dsn up to a database
    Cnn1.Open "DSN=nwind;UID=sa;PWD="
    Set adoCmd.ActiveConnection = Cnn1
    ' I'm sure there's a much more graceful 
    '     way to do this....
    adoCmd.CommandText = "select TableName=t1.[name], ColumnName=c1.[name], datatype=(select a1.[name] from dbo.systypes as a1 where a1.xusertype = c1.xusertype), c1.isnullable, c1.length, c1.colid from dbo.syscolumns as c1 inner join dbo.sysobjects as t1 On c1.id = t1.id where t1.xtype = 'U'"
    Set tmpRST = adoCmd.Execute
    sXML = "<?xml version=""1.0""?><TABLEs>"
    Dim sTable
    Dim iColCount
    Dim intIterator
    iColCount = tmpRST.Fields.Count - 1
    sTable = tmpRST.Fields("TableName")
    sXML = sXML & "<TABLE><name>" & tmpRST("TableName") & "</name>"
    Do While Not tmpRST.EOF
    if tmpRST.Fields("TableName") <> sTable Then
    sXML = sXML & "</TABLE><TABLE><name>" & tmpRST.Fields("TableName") & "</name>"
    End if
    sXML = sXML & "<COLumn>"
    For intIterator = 1 To iColCount
    sXML = sXML & "<" & tmpRST.Fields(intIterator).Name & ">" & tmpRST.Fields(intIterator) & "</" & tmpRST.Fields(intIterator).Name & ">"
    Next
    sXML = sXML & "</COLumn>"
    sTable = tmpRST.Fields("TableName")
    tmpRST.MoveNext
    Loop
    sXML = sXML & "</TABLE></TABLEs>"
    Response.Write sXML
    %>

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
2/21/2001 4:40:09 PM:Brandon McPherson
An added note: the tag capitalization 
is happening in PSC's code formatter. 
You'll need to change the tags to 
lowercase when you run the demo. And as 
always, please vote if you like it! :)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/21/2001 7:43:48 PM:Chris Maynard
That's cool! =D
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.