SELECT statement pulls field names - how to avoid?
SELECT statement pulls field names - how to avoid?
am 24.01.2007 01:44:26 von Billy
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....
Package Tracking Results - Client Feed
<%
' 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") & "
")
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
%>
Re: SELECT statement pulls field names - how to avoid?
am 24.01.2007 09:36:19 von Mike Brind
"Billy" wrote in message
news:1169599466.831734.201300@k78g2000cwa.googlegroups.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....
>
>
>
>
>
> Package Tracking Results - Client Feed
>
>
>
>
> <%
> ' 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") & "
")
> 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/quickref/ado_intro.h tml
--
Mike Brind
Re: SELECT statement pulls field names - how to avoid?
am 24.01.2007 12:35:22 von reb01501
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"
Re: SELECT statement pulls field names - how to avoid?
am 26.01.2007 23:04:17 von Billy
Thanks all. Commenting out the section that produced the headers
worked.
On Jan 24, 6:35 am, "Bob Barrows [MVP]"
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"