SELECT statement - How to not get column field names?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Billy

    SELECT statement - How to not get column field names?

    I do a SELECT * from table command in an ASP page to build a text file
    out on our server, but the export is not to allow a field name rows of
    records. The first thing I get is a row with all the field names. Why
    do these come in if they are not part of the table records? How do I
    eliminate this from being produced? Here's the ASP code....


    <html>

    <head>
    <title>Packag e Tracking Results - Client Feed</title>
    </head>

    <body>

    <%
    ' define variables
    dim oConn ' ADO Connection
    dim oRSc ' ADO Recordset - Courier table
    dim cSQLstr ' SQL string - Courier table
    dim oRSn ' ADO Recordset - NAN table
    dim nSQLstr ' SQL string - NAN table
    dim objFSO ' FSO Connection
    dim objTextFile ' Text File

    ' set and define FSO connection and text file object location
    Set objFSO = CreateObject("S cripting.FileSy stemObject")
    'Set objTextFile =
    objFSO.CreateTe xtFile(Server.M apPath("textfil e.txt"))
    'Response.Write (Server.MapPath ("textfile.txt" ) & "<br />")
    Set objTextFile = objFSO.OpenText File("C:\textfi le.txt",2)

    ' write text to text file
    'objTextFile.Wr iteLine "This text is in the file ""textfile.txt" "!"


    ' SQL strings for Courier and NAN tables
    cSQLstr = "SELECT * FROM Courier"

    ' set and open ADO connection & oRSc recordsets
    set oConn=Server.Cr eateObject("ADO DB.connection")
    oConn.Open "DRIVER={Micros oft Access Driver (*.mdb)};DBQ=" &
    "c:/Database/QaTracking/QaTracking.mdb" & ";"
    set oRSc=Server.Cre ateObject("ADOD B.Recordset")
    oRSc.Open cSQLstr, oConn

    Response.Conten tType = "text/plain"
    Dim i, j, tmp
    If Not oRSc.EOF Then
    For i = 1 To oRSc.Fields.Cou nt
    objTextFile.Wri te oRSc.Fields(i-1).Name
    If i < oRSc.Fields.Cou nt Then
    objTextFile.Wri te " "
    End If
    Next
    objTextFile.Wri teLine
    While Not oRSc.EOF
    For i = 1 To oRSc.Fields.Cou nt
    If oRSc.Fields(i-1) <"" Then
    tmp = oRSc.Fields(i-1)
    ' If TypeName(tmp) = "String" Then
    ' objTextFile.Wri te "" &_
    'Replace(oRSc.F ields(i-1),vbCrLf,"") & ""
    ' Else
    objTextFile.Wri te oRSc.Fields(i-1)
    ' End If
    End If
    If i < oRSc.Fields.Cou nt Then
    objTextFile.Wri te " "
    End If
    Next
    objTextFile.Wri teLine
    oRSc.MoveNext
    Wend
    End If
    objTextFile.Clo se
    Set objTextFile = Nothing
    Set objFSO = Nothing
    oRSc.Close
    Set oRSc = Nothing
    oConn.Close
    Set oConn = Nothing
    %>

    </body>
    </html>

  • Plamen Ratchev

    #2
    Re: SELECT statement - How to not get column field names?

    Hi,

    If I understand correctly you want to eliminate the first row in the result
    text file which contains the field names. In your code you have a loop that
    writes those to the text file:
    For i = 1 To oRSc.Fields.Cou nt
    objTextFile.Wri te oRSc.Fields(i-1).Name
    If i < oRSc.Fields.Cou nt Then
    objTextFile.Wri te " "
    End If
    Next
    objTextFile.Wri teLine
    Just comment out the section above and it should no longer write the field
    names to the output file.

    Regards,

    Plamen Ratchev



    Comment

    Working...