Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > BOOK: Beginning ASP 3.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 29th, 2004, 03:11 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Command text was not set for the command object.

Hi all,
        I have problem with the following code.. It gives error at command.execute statement, but I guess it's the SQL statement.I could not think what is wrong with this statement...Please help anyone..

Dim objCmd, rsBid
    Set objCmd = Server.CreateObject("ADODB.Command")
    Set objCmd.ActiveConnection = objConn
    objCmd.CommandType = adCmdText
....
....
objCmd.CommandText = "SELECT Max(bid.BidAmount) as MaxBidAmount, " & _
                    "Max(bid.Timestamp) as LastBidTime from bid " & _
                    " WHERE ItemID = ' " & rsItems ("ItemID") &" ' "

      Set rsBid = objCmd.Execute <-- Error Line If IsNull( rsBid("MaxBidAmount") ) Then
        Response.Write _
          "<TD COLSPAN=2>No bids placed</TD>"
      Else
....
...
....


  #2 (permalink)  
Old October 30th, 2004, 01:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Deepa,

You are missing the FROM clause in the SELECT statement.

Check online documentation for syntax. It should be in this order
Code:
Select COLUMNLIST
From TABLENAME
where CRITERIA
Cheers!

_________________________
- Vijay G
Strive for Perfection
  #3 (permalink)  
Old October 31st, 2004, 08:29 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
    Thanks for your response.But if you look my SQL statement is in the order you said it should be. Do you think as I used Max function ,I should use group by also ?

  #4 (permalink)  
Old November 1st, 2004, 03:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I didnot notice that it has the FROM class, sorry about that.

Can you post on what exactly the ERROR that you see there. And no mention about what database you use(Access/SQL server???). May be you can try executing the output of the following code directly on to your database.
Code:
Response.write "SELECT Max(bid.BidAmount) as MaxBidAmount, " & _
                    "Max(bid.Timestamp) as LastBidTime from bid " & _
                    " WHERE ItemID = ' " & rsItems ("ItemID") &" ' "
Response.End
Set rsBid = objCmd.Execute
Looks like the SPACE before and after the rs(Items("ItemID") or the single quotes itself could be the cause for that. What is the datatype of ItemId on your BID table?

Cheers!

_________________________
- Vijay G
Strive for Perfection
  #5 (permalink)  
Old November 2nd, 2004, 10:51 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
    I get the following Error.I am using Access 2000 and ItemId datatype is Number

Error Type:
Microsoft JET Database Engine (0x80040E0C)
Command text was not set for the command object.
/KhandkeOnline/Images/classified/BrowseListings.asp, line 86

Actually I changed the code little bit. but it's still giving the same error.Here is the new Code

<%
  Dim rsItems
  strSQL = "SELECT * FROM Item " & _
           "WHERE ExpirationDate > #" & FormatDateTime(Now,2) & "# " & _
           "AND ItemStatus = 'Active';"

  Set rsItems = Server.CreateObject("ADODB.Recordset")
  rsItems.Open strSQL, objConn

  If Not rsItems.EOF Then
    Response.Write _
      "<TABLE BORDER=""1"" CELLSPACING=""3"" CELLPADDING=""3"" FONT SIZE=""2"">" & _
      " <TR>" & _
      " <TH>Item ID"
               If Session("PersonID") <> "" Then
                 Response.Write "<BR>Click to Bid"
               End If
           Response.Write "</TH>" & _
      " <TH>Name</TH>" & _
      " <TH>Asking Price</TH>" & _
      " <TH>Listing Date</TH>" & _
      " <TH>Current Bid</TH>" & _
      " <TH>Bid Time</TH>" & _
      " </TR>"
    Dim objCmd, rsBid
    Set objCmd = Server.CreateObject("ADODB.Command")
    Set objCmd.ActiveConnection = objConn
    strSQL="SELECT Max(BidAmount) as MaxBidAmount, " & _
                            "Max(Timestamp) as LastBidTime from bid"
    objCmd.CommandType = adCmdText

    Do While Not rsItems.EOF
      Response.Write "<TR ALIGN=CENTER>"
      If Session("PersonID") <> "" Then
        Response.Write _
          "<TD><A HREF=""Bid.asp?Item=" & rsItems("ItemID") & """>" & _
          rsItems("ItemID") & "</A></TD>"
      Else
        Response.Write "<TD>" & rsItems("ItemID") & "</TD>"
      End If

      Response.Write _
        "<TD>" & rsItems("ItemName") & "</TD>" & _
        "<TD>" & FormatCurrency(rsItems("AskingPrice")) & "</TD>" & _
        "<TD>" & FormatDateTime(rsItems("ListingDate"),2) & "</TD>" & _

        objCmd.CommandText = strSQL & " where ItemID = " & rsItems("ItemID") & ";"
        Set rsBid = objCmd.Execute
      If IsNull( rsBid("MaxBidAmount") ) Then
        Response.Write _
          "<TD COLSPAN=2>No bids placed</TD>"
      Else
        Response.Write _
          "<TD>" & FormatCurrency(rsBid("MaxBidAmount")) & "</TD>" & _
          "<TD>" & rsBid("LastBidTime") & "</TD>"
        Dim strSQL2, rsHighBidder
        strSQL2 = "SELECT BidderID FROM bid " & _
                  "WHERE ItemID = " & rsItems("ItemID") &" ORDER BY Timestamp DESC"
        objCmd.CommandType = adCmdText
        objCmd.CommandText = strSQL2
        Set rsHighBidder = objCmd.Execute
        If rsHighBidder("BidderID") = Session("PersonID") Then
          Response.Write "<TD>" & _
                         "You are the current high bidder</TD>"
        End If
        rsHighBidder.Close
        Set rsHighBidder = Nothing
      End If
      rsBid.Close
      Set rsBid = Nothing
      Response.Write "</TR>"
      rsItems.MoveNext
    Loop
    Response.Write "</TABLE>"
    rsItems.close
    Set rsItems = Nothing
  Else
    Response.Write "<CENTER><H2>No items currently for sale</H2></CENTER>"
  End If
%>

  #6 (permalink)  
Old November 2nd, 2004, 05:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Deepa,

As the error is straight forward, did you forget to set the strSQL to the command object? As per you code, you have set the command's active connection, commandtype etc, but you haven't assigned the strSQL's value to its commandtext as you did in your first post of this thread.
Code:
    Set objCmd = Server.CreateObject("ADODB.Command")
    Set objCmd.ActiveConnection = objConn
    strSQL="SELECT Max(BidAmount) as MaxBidAmount, " & _
                            "Max(Timestamp) as LastBidTime from bid"
    objCmd.CommandType = adCmdText
    Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command text was not set for the command object Sheraz Khan Classic ASP Databases 2 May 29th, 2007 12:57 AM
Issues with Command Object and Parameters BSkelding Crystal Reports 0 May 2nd, 2007 10:29 AM
Help! 'Command object error' sisi Classic ASP Databases 4 May 25th, 2004 06:23 PM
command object scrolling qwprince Classic ASP Databases 3 July 24th, 2003 09:29 AM



All times are GMT -4. The time now is 05:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.