469,270 Members | 1,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

SELECT statement pulls field names - how to avoid?

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>Package 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("Scripting.FileSystemObject")
'Set objTextFile =
objFSO.CreateTextFile(Server.MapPath("textfile.txt "))
'Response.Write (Server.MapPath("textfile.txt") & "<br />")
Set objTextFile = objFSO.OpenTextFile("C:\textfile.txt",2)

' write text to text file
'objTextFile.WriteLine "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.CreateObject("ADODB.connection")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &
"c:/Database/QaTracking/QaTracking.mdb" & ";"
set oRSc=Server.CreateObject("ADODB.Recordset")
oRSc.Open cSQLstr, oConn

Response.ContentType = "text/plain"
Dim i, j, tmp
If Not oRSc.EOF Then
For i = 1 To oRSc.Fields.Count
objTextFile.Write oRSc.Fields(i-1).Name
If i < oRSc.Fields.Count Then
objTextFile.Write " "
End If
Next
objTextFile.WriteLine
While Not oRSc.EOF
For i = 1 To oRSc.Fields.Count
If oRSc.Fields(i-1) <"" Then
tmp = oRSc.Fields(i-1)
' If TypeName(tmp) = "String" Then
' objTextFile.Write "" &_
'Replace(oRSc.Fields(i-1),vbCrLf,"") & ""
' Else
objTextFile.Write oRSc.Fields(i-1)
' End If
End If
If i < oRSc.Fields.Count Then
objTextFile.Write " "
End If
Next
objTextFile.WriteLine
oRSc.MoveNext
Wend
End If
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing
oRSc.Close
Set oRSc = Nothing
oConn.Close
Set oConn = Nothing
%>

</body>
</html>

Jan 24 '07 #1
3 2547

"Billy" <Us*****@hotmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
>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>Package 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("Scripting.FileSystemObject")
'Set objTextFile =
objFSO.CreateTextFile(Server.MapPath("textfile.txt "))
'Response.Write (Server.MapPath("textfile.txt") & "<br />")
Set objTextFile = objFSO.OpenTextFile("C:\textfile.txt",2)

' write text to text file
'objTextFile.WriteLine "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.CreateObject("ADODB.connection")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &
"c:/Database/QaTracking/QaTracking.mdb" & ";"
set oRSc=Server.CreateObject("ADODB.Recordset")
oRSc.Open cSQLstr, oConn

Response.ContentType = "text/plain"
Dim i, j, tmp
If Not oRSc.EOF Then
Remove the lines below. They are the ones that write out the name of the
fields.
For i = 1 To oRSc.Fields.Count
objTextFile.Write oRSc.Fields(i-1).Name
If i < oRSc.Fields.Count Then
objTextFile.Write " "
End If
Next
objTextFile.WriteLine
Have a look at the ADO Field Object's properties. It might help you see
what you are doing:

http://www.devguru.com/Technologies/...ado_intro.html

--
Mike Brind
Jan 24 '07 #2
Billy wrote:
I do a SELECT *
:-)
Well, nothing to do with your problem, but that's mistake #1
http://www.aspfaq.com/show.asp?id=2096
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.
Don't write them if you don't want them. You control what gets written.
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....
' set and open ADO connection & oRSc recordsets
set oConn=Server.CreateObject("ADODB.connection")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &
"c:/Database/QaTracking/QaTracking.mdb" & ";"
Again, nothing to do with your problem, but this is mistake #2
http://www.aspfaq.com/show.asp?id=2126
set oRSc=Server.CreateObject("ADODB.Recordset")
oRSc.Open cSQLstr, oConn

Response.ContentType = "text/plain"
Dim i, j, tmp
If Not oRSc.EOF Then
*****************************************
For i = 1 To oRSc.Fields.Count
objTextFile.Write oRSc.Fields(i-1).Name
If i < oRSc.Fields.Count Then
objTextFile.Write " "
End If
Next
****************************************

As I said above, if you don't want the field names, don't write them. You
are in control of what is written. Just remove this loop.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jan 24 '07 #3
Thanks all. Commenting out the section that produced the headers
worked.

On Jan 24, 6:35 am, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
Billy wrote:
I do a SELECT *:-)
Well, nothing to do with your problem, but that's mistake #1http://www.aspfaq.com/show.asp?id=2096
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.Don't write them if you don't want them. You control what gets written.
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....
' set and open ADO connection & oRSc recordsets
set oConn=Server.CreateObject("ADODB.connection")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &
"c:/Database/QaTracking/QaTracking.mdb" & ";"Again, nothing to do with your problem, but this is mistake #2http://www.aspfaq.com/show.asp?id=2126
set oRSc=Server.CreateObject("ADODB.Recordset")
oRSc.Open cSQLstr, oConn
Response.ContentType = "text/plain"
Dim i, j, tmp
If Not oRSc.EOF Then***************************************** For i = 1 To oRSc.Fields.Count
objTextFile.Write oRSc.Fields(i-1).Name
If i < oRSc.Fields.Count Then
objTextFile.Write " "
End If
Next****************************************

As I said above, if you don't want the field names, don't write them. You
are in control of what is written. Just remove this loop.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jan 26 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Karzy | last post: by
8 posts views Thread by Perre Van Wilrijk | last post: by
2 posts views Thread by phpuser32423 | last post: by
3 posts views Thread by Tcs | last post: by
5 posts views Thread by freddy | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.