Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Command text was not set for the command object.


Message #1 by "Sabina Ranjit" <chimsii@h...> on Thu, 5 Sep 2002 04:31:08
Hi everyone!

I'm trying to build a dynamic site, using ASP(JavaScript), MS Access 
Database. When trying to make a results page for a search form, I keep 
getting the following error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E0C)
Command text was not set for the command object.

My code is as follows: Could anyone help me out here, what have I done 
wrong?


<%@LANGUAGE="JAVASCRIPT"%>

<%

var StrconnName = "dsn=connName;"

var category = Request.QueryString("Category")
var keyword =Request.QueryString("Keyword")
var CurrID;
var row = Request.QueryString("Row")
var counter = row;
%>
<%
var Search_Word = "%";

if(String(Request.QueryString("Keyword")) != "undefined" &&
String(Request.QueryString ("Keyword")) != "") {
Search_Word = Request.QueryString("Keyword");}
%>
<%
var rsResults = Server.CreateObject("ADODB.Recordset");
rsResults.ActiveConnection = StrconnName ;
if(category == 'Services')
	rsResults.Source = "SELECT *  FROM Services  WHERE 
ServiceNameLIKE  "+ "'" +Search_Word+ "%'";
else if (category == 'Products')
	rsResults.Source = "SELECT *  FROM Products WHERE Description 
LIKE  "+ "'" +Search_Word+ "%'";

	
rsResults.CursorType = 0;
rsResults.CursorLocation = 2;
rsResults.LockType = 1;
rsResults.Open(); --> The Error is in this line

Message #2 by "Ken Schaefer" <ken@a...> on Thu, 5 Sep 2002 14:19:53 +1000
You have code that says:

: if(category == 'Services')
: rsResults.Source = "SELECT *  FROM Services  WHERE
: ServiceNameLIKE  "+ "'" +Search_Word+ "%'";
: else if (category == 'Products')
: rsResults.Source = "SELECT *  FROM Products WHERE Description
: LIKE  "+ "'" +Search_Word+ "%'";

What if category is neither Services nor Products?!? Then rsResults.Source
has no value.

Also, you should never open a recordset by setting the ActiveConnection to a
connection string. Always set it to a connection *object*. Why? Because if
you use a connection string you are defeating connection pooling:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q191572
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmdac/html
/pooling2.asp

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Sabina Ranjit" <chimsii@h...>
Subject: [access_asp] Command text was not set for the command object.


: Hi everyone!
:
: I'm trying to build a dynamic site, using ASP(JavaScript), MS Access
: Database. When trying to make a results page for a search form, I keep
: getting the following error:
:
: Microsoft OLE DB Provider for ODBC Drivers (0x80040E0C)
: Command text was not set for the command object.
:
: My code is as follows: Could anyone help me out here, what have I done
: wrong?
:
:
: <%@LANGUAGE="JAVASCRIPT"%>
:
: <%
:
: var StrconnName = "dsn=connName;"
:
: var category = Request.QueryString("Category")
: var keyword =Request.QueryString("Keyword")
: var CurrID;
: var row = Request.QueryString("Row")
: var counter = row;
: %>
: <%
: var Search_Word = "%";
:
: if(String(Request.QueryString("Keyword")) != "undefined" &&
: String(Request.QueryString ("Keyword")) != "") {
: Search_Word = Request.QueryString("Keyword");}
: %>
: <%
: var rsResults = Server.CreateObject("ADODB.Recordset");
: rsResults.ActiveConnection = StrconnName ;
: if(category == 'Services')
: rsResults.Source = "SELECT *  FROM Services  WHERE
: ServiceNameLIKE  "+ "'" +Search_Word+ "%'";
: else if (category == 'Products')
: rsResults.Source = "SELECT *  FROM Products WHERE Description
: LIKE  "+ "'" +Search_Word+ "%'";
:
:
: rsResults.CursorType = 0;
: rsResults.CursorLocation = 2;
: rsResults.LockType = 1;
: rsResults.Open(); --> The Error is in this line



  Return to Index