ASP Help...

Status
Not open for further replies.

E3

Ars Centurion
387
Public Function GetAuctionItemsBySearch(SearchText, PathToPage)
Set Conn = CreateObject("ADODB.Connection")
Conn.ConnectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=" & svrName _
& ";INITIAL CATALOG=" & dbName & ";USER ID=" & userId _
& ";PASSWORD=" & passWd
Conn.Open
Dim RSItems As ADODB.Recordset
Dim TempReturn As String

Set RSItems = Conn.Execute("Select auctionitem_id,productname, " _
& "currentbid,numbid,closingdate from auctionitem " _
& "where productname Like '%" & SearchText & "%' or " _
& "description Like '&" & SearchText & "%'")

TempReturn = "<TABLE BORDER=1 CELLSPACING=3 CELLPADDING=1 WIDTH = 465>" _
& "<TR><TD WIDTH=143>

Product Name" _
& "
</TD><TD WIDTH=90>

Current Bid" _
& "
</TD><TD WIDTH=51>

# Bids" _
& "
</TD><TD WIDTH=148>

Closes" _
& "
</TD></TR>" & vbNewLine
Do Until RSItems.EOF
TempReturn = TempReturn & "<TR>" _
& "<TD WIDTH=143>

" & RSItems("productname") & "</TD>" _
& "<TD WIDTH=90>

" _
& FormatCurrency(RSItems("currentbid")) & "</TD>" _
& "<TD WIDTH= 51>

" _
& RSItems("numbid") & "</TD>" _
& "<TD WIDTH= 148>

" _
& RSItems("closingdate") & "</TD></TR>" & vbNewLine

RSItems.MoveNext
Loop
TempReturn = TempReturn & "</TABLE>" & vbNewLine
GetAuctionItemsBySearch = TempReturn

End Function

Public Function GetSubCategoriesBySearch(SearchText, PathToPage)
Dim Conn
Dim svrName ' database server name
Dim dbName ' database name
Dim userId ' user id
Dim passWd ' password


'Initialise variables
svrName = "rox-oin2stqk26k"
dbName = "fyp"
userId = "abc"
passWd = "abc"

'Open connection to DB
Set Conn = CreateObject("ADODB.Connection")
Conn.ConnectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=" & svrName _
& ";INITIAL CATALOG=" & dbName & ";USER ID=" & userId _
& ";PASSWORD=" & passWd
Conn.Open
Dim RSCategories As ADODB.Recordset
Dim TempReturn As String
Dim RowCount

Set RSCategories = Conn.Execute("Select cat_name from " _
& "Categories where cat_name = '%" _
& SearchText & "%' Order by cat_name")
TempReturn = "<TABLE BORDER = 0 CELLSPACING=0 CELLPADDING=2 Width = 120 > " _
& "<TR><TD> WIDTH=116 BGCOLOR =""#cccc99"">

" _
& "" _
& "Sub Categories
</TD></TR>" & vbNewLine
RowCount = 1
Do Until RSCategories.EOF
TempReturn = TempReturn & "<TR>" _
& "<TD WIDTH=116 BGCOlOR=""#cccc99"">

" _
& RSCategories("cat_name") & "
</TD>" _
& "</TR>" & vbNewLine
RSCategories.MoveNext
RowCount = RowCount + 1
Loop
If RowCount < 10 Then
Do Until RowCount = 10
TempReturn = TempReturn & "<TR>" _
& "<TD BGCOLOR=""#CCCC99""> </TD>" _
& "</TR>" & vbNewLine
RSCategories.MoveNext
RowCount = RowCount + 1
Loop
End If
TempReturn = TempReturn & "</Table>"
GetSubCategoriesBySearch = TempReturn
End Function



Dim MyAuction
Dim ThePath
Dim TheSubs
Dim TheProducts

Set MyAuction= Server.CreateObject("Auction.AuctionData")


If not IsEmpty(Request.Form("GoSearch")) Then
ThePath = ""
TheSubs = MyAuction.GetSubCategoriesBySearch(Request.Form("SearchText"),"./auction_list.asp")
TheProducts = MyAuction.GetAuctionItemsBySearch(Request.Form("SearchText"),"./auction_list.asp")

ElseIf not IsEmpty(Request.Form("GoBrowse")) Then
ThePath= MyAuction.GetCategoryPath(Request.Form("Category"),"./auction_list.asp")
TheProducts= MyAuction.GetAuctionItemsByCategory(Request.Form("Category"),"./auction_list.asp")

Elseif not IsEmpty(Request.QueryString("CategoryName")) Then
ThePath = MyAuction.GetCategoryPath(Request.QueryString("CategoryName"),"./auction_list.asp")
TheSubs = MyAuction.GetSubCategories(Request.QueryString("CategoryName"),"./auction_list.asp")
TheProducts = MyAuction.GetAuctionItemsByCategory(Request.QueryString("CategoryName"),"./auctionitem.asp")

Else
Response.Redirect "./auction_menu.asp"

End If


The first file is component I ve created using VB. In it are similiar methods/functions. For method, i have a new connection to DB. The second asp file is calling a method from the component. I checked and checked but I have this recordset error??????????? This error is quite new to me and I can't quite solve my current problem

Error Type:
ADODB.Recordset (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/Auction_List.asp, line 14


Any idea on whats wrong with it??



:confused: :confused: :mad:
 

Aeirould

Ars Tribunus Angusticlavius
7,535
Subscriptor
In your categories by search routine, you're executing a MoveNext after the RS.EOF is already satisfied. I'd suspect that's it.

code:<HR>
Code:
RSCategories.MoveNext
RowCount = RowCount + 1
Loop
If RowCount < 10 Then
Do Until RowCount = 10
TempReturn = TempReturn & "<TR>" _
& "<TD BGCOLOR=""#CCCC99""> </TD>" _
& "</TR>" & vbNewLine
RSCategories.MoveNext

Oh, btw, you really need to clean up after yourself. CLose your recordsets and connections when you're done with 'em and set 'em to nothing... it'll help speed the garbage collection and will enhance the benefits of connection pooling.

You're also using almost exclusively Variants (by not typing the variables) in the component. This is bad... it slows you down quite a bit more than you need to. If you were having issues getting the data from ASP to VB when typing the variables (as is common), just use ByVal in your Function declaration.

You also are polling the Request.(x) collections too often... VBScript is an interpreted language and will not optimize that bit for you. If you're gonna use a value from the collection three times, pull it to a local variable and then propagate it from there.
 

E3

Ars Centurion
387
Thanks for the replies,ppl.
I will clean it up and try again.
In your categories by search routine, you're executing a MoveNext after the RS.EOF is already satisfied. I'd suspect that's it.
Do Until RSCategories.EOF
TempReturn = TempReturn & "<TR>" _
& "<TD WIDTH=116 BGCOlOR=""#cccc99"">

" _
& RSCategories("cat_name") & "
</TD>" _
& "</TR>" & vbNewLine
RSCategories.MoveNext
RowCount = RowCount + 1
Loop

Its the files is eof, the codes below it shouldn't be executing and the loop is broken?.
Am I right?
 
Status
Not open for further replies.