473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2694

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Karzy | last post by:
I would like to have a form that gives the user choices for selection parameters for email, printing etc. A real simple example: Give me all ______ who ______ when _______ where _______ I...
8
by: Perre Van Wilrijk | last post by:
Hello, I have 2 ways of updating data I'm using often 1) via a cursor on TABLE1 update fields in TABLE2 2) via an some of variables ... SELECT @var1=FLD1, @var2=FLD2 FROM TABLE1 WHERE...
7
by: CharlesEF | last post by:
Hi All, I have run into another problem that is eating my lunch. Should be simple but I am having one heck of a time. Please look at this SELECT statement: SELECT FROM States WHERE ] =...
2
by: phpuser32423 | last post by:
Hi everyone Is it by any chance possible to use mysql and php to auto create the content for drop-down lists on forms by retrieving the values from a database? The reason i ask is that on a site...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
5
by: freddy | last post by:
I have a select statement like this: string Select = "Select TableofContents, DataOwner, Delegates From NYC"; and it work fine, but if I was to put a space in like this: string Select = "Select...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
5
by: OldBirdman | last post by:
I am attempting to assign a .RowSource to a ListBox using an SQL statement. I want to build the SQL statement "On-the-Fly", based on values in several controls on the form. I would like to restrict...
4
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.