"Dern, can't remember that there command."

D

Dave

Database with four fields. I only want to pull data from two specific
fields.
Can't think of the command to specify particular fields.

Dave
 
B

Bob Barrows

Dave said:
Database with four fields. I only want to pull data from two specific
fields.
Can't think of the command to specify particular fields.

Dave

? Just list them in the Select clause of your query ... ?
 
D

Dave

Bob,
Tried it and received an error. Here's the code I'm using:

strQuery="SELECT TB1 TB2 FROM Guestbook ORDER BY " &StrSort

Here's the error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in
query expression 'TB1 TB2'.
/regweb/dpg/Content.asp, line 46

Here's line 46:

rst.Open strQuery, strProvider
 
J

Jones Ambrosi

You need using commas between name of coluns: select tb1, tb2 from ...

Bob,
Tried it and received an error. Here's the code I'm using:

strQuery="SELECT TB1 TB2 FROM Guestbook ORDER BY " &StrSort

Here's the error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in
query expression 'TB1 TB2'.
/regweb/dpg/Content.asp, line 46

Here's line 46:

rst.Open strQuery, strProvider



Bob Barrows said:
? Just list them in the Select clause of your query ... ?
 
B

Bob Barrows

Well, you DO have to separate them by commas ... :)
strQuery="SELECT TB1, TB2 FROM Guestbook ORDER BY " &StrSort
Bob,
Tried it and received an error. Here's the code I'm using:

strQuery="SELECT TB1 TB2 FROM Guestbook ORDER BY " &StrSort

Here's the error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
operator) in query expression 'TB1 TB2'.
/regweb/dpg/Content.asp, line 46

Here's line 46:

rst.Open strQuery, strProvider



Bob Barrows said:
? Just list them in the Select clause of your query ... ?
 
D

Dave

I did get a result, but not exactly what I need. I updated the code with a
comma; but the page only returns information
from TB2.
TB1 doesn't habla aspanol. :)

Dave


Bob Barrows said:
Well, you DO have to separate them by commas ... :)
strQuery="SELECT TB1, TB2 FROM Guestbook ORDER BY " &StrSort
Bob,
Tried it and received an error. Here's the code I'm using:

strQuery="SELECT TB1 TB2 FROM Guestbook ORDER BY " &StrSort

Here's the error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
operator) in query expression 'TB1 TB2'.
/regweb/dpg/Content.asp, line 46

Here's line 46:

rst.Open strQuery, strProvider



Bob Barrows said:
Dave wrote:
Database with four fields. I only want to pull data from two
specific fields.
Can't think of the command to specify particular fields.

Dave

? Just list them in the Select clause of your query ... ?
 
D

Dave

This is the updated code that I'm using:

strQuery="SELECT TB1, TB2 FROM Guestbook"

Only recieving information from TB2 now; TB1 doesn't appear in the results.

I don't see anything else wrong with the ASP code. The page does not cache
and has a visitor counter, so I know I'm see up-to-date information. Below
is the page code. It's long.


<% @Language=VBScript %>
<html dir=ltr>
<head>
<title>View Guest Book</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" bottomMargin=0 leftMargin=0
rightMargin=0 topmargin=0 marginheight="0" marginwidth="0">
<%
Response.ExpiresAbsolute = #2000-01-01#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, must-revalidate"
%>

<%
strQuery="SELECT TB1, TB2 FROM Guestbook"

'Database path statement describing the driver to use and the path to the
desired database.
strProvider = "Driver=Microsoft Access Driver (*.mdb);
DBQ=F:\RegWeb\Databases\guestbook.mdb;"
IF Request("ID") <> "" THEN
strIDNum=Request("ID")

'Creates an instance of an Active server component
set objConn = server.createobject("ADODB.Connection")

'Opens the connection to the data store
objConn.Open strProvider

'Instantiate Command object and use ActiveConnection property to attach
connection to Command object
set cm = Server.CreateObject("ADODB.Command")
cm.ActiveConnection = objConn

'Define SQL query
cm.CommandText = "DELETE FROM Guestbook WHERE ID = " &strIDNum
cm.Execute
END IF

'Instantiate a Recordset object and open a recordset using the Open method
Set rst = Server.CreateObject("ADODB.recordset")
rst.Open strQuery, strProvider
%>

<table border=1 cellspacing=0 cellpadding=0 width=260 bordercolor="#658BB0"
bgcolor="#E3EAF0">
<%
ON ERROR RESUME NEXT
IF rst.EOF THEN
Response.Write "There are no entries in the database."
ELSE%>
<%
WHILE NOT rst.EOF %>
<tr>
<%
'Response.Write "<td align=left valign=top bgcolor='#ffffff'>First Column
FIELD</td>"
FOR i = 1 to rst.fields.count - 1
Response.Write "<tr><td align=left valign=top bgcolor='#ffffff'>" &
rst(i)&"</td>"
NEXT
rst.MoveNext
WEND
END IF
%>
</table>
<% Set pageCount = Server.CreateObject("MSWC.PageCounter") %>
<% pageCount.PageHit %>
You are visitor number <% =pageCount.Hits %> to this Web site.

</body>
</html>




Dave said:
I did get a result, but not exactly what I need. I updated the code with a
comma; but the page only returns information
from TB2.
TB1 doesn't habla aspanol. :)

Dave


Bob Barrows said:
Well, you DO have to separate them by commas ... :)
strQuery="SELECT TB1, TB2 FROM Guestbook ORDER BY " &StrSort
Bob,
Tried it and received an error. Here's the code I'm using:

strQuery="SELECT TB1 TB2 FROM Guestbook ORDER BY " &StrSort

Here's the error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
operator) in query expression 'TB1 TB2'.
/regweb/dpg/Content.asp, line 46

Here's line 46:

rst.Open strQuery, strProvider



Dave wrote:
Database with four fields. I only want to pull data from two
specific fields.
Can't think of the command to specify particular fields.

Dave

? Just list them in the Select clause of your query ... ?
 
B

Bob Barrows

The problem is right here:
Dave said:
FOR i = 1 to rst.fields.count - 1

The Fields collection (as is the case with nearly every collection I can
think of) has a zero-based index. The first field has an index of 0, the
second 1, etc. So in this line, you are telling it to start from the second
field: not what you intended. Tell it to start from zero:
FOR i = 0 to fields.count - 1

HTH,
Bob Barrows
 
D

Dave

Ahh. Gracias!!! Problem solved. Thank you everyone for your attention steps
to the solution.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top