Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Comma delimited Record Set
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

mafifi
Junior Member

USA
308 Posts

Posted - 11 June 2007 :  23:41:32  Show Profile  Send mafifi an ICQ Message
I am querying a database and returning the records in a comma delimited format as the records will be is used later in a JavaScript. The records are being returned as:


("Record 1", "ID 1", "Record 2", "Record ID 2",   );



I want to be able to ignore the last comma and space before closing the parentheses. Here is my code:



<% 
Dim Text1, Text2
Text1 = "parent._ac_rpc(""KBAC"", "
Text2 = ");"
pm.SetConnection = "MyConnection"
pm.SetSource = "SELECT	tblBooks.Book_ID, tblBooks.BookTitle, tblBooks.Active_Flag FROM tblBooks WHERE (tblBooks.BookTitle LIKE 'MyVariable') AND (tblBooks.Active_Flag = 'A')"
If (pm.InitRS = True) Then
Response.Write Text1
Do
(LINE 10) Response.Write """ & pm.GetItem("BookTitle") & """, """ & pm.GetItem("Book_ID") & """, "
pm.MoveNextItem
Loop Until pm.CurrentPageRowEnd
Response.Write Text2
Set pm = Nothing
End If
 %>




I think the problem is with line 10.

Regards,

Mo

Edited by - mafifi on 11 June 2007 23:47:41

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 12 June 2007 :  03:41:30  Show Profile  Visit HuwR's Homepage
try doing it like this

<% 
Dim Text1, Text2
Text1 = "parent._ac_rpc(""KBAC"""
Text2 = ");"
pm.SetConnection = "MyConnection"
pm.SetSource = "SELECT	tblBooks.Book_ID, tblBooks.BookTitle, tblBooks.Active_Flag FROM tblBooks WHERE (tblBooks.BookTitle LIKE 'MyVariable') AND (tblBooks.Active_Flag = 'A')"
If (pm.InitRS = True) Then
Response.Write Text1
Do
Response.Write ", "" & pm.GetItem("BookTitle") & """, """ & pm.GetItem("Book_ID") & """"
pm.MoveNextItem
Loop Until pm.CurrentPageRowEnd
Response.Write Text2
Set pm = Nothing
End If
 %>

(lines changed are in red)
that should stop it putting the extra , at the end.
Go to Top of Page

mafifi
Junior Member

USA
308 Posts

Posted - 12 June 2007 :  08:33:54  Show Profile  Send mafifi an ICQ Message
Works great, thank you.

Regards,

Mo
Go to Top of Page

mafifi
Junior Member

USA
308 Posts

Posted - 12 June 2007 :  19:16:18  Show Profile  Send mafifi an ICQ Message
Follow up question though. I am having a very hard time escaping the double quote which included in the (BookTitle) field. I tried different things including replacing the (") with the (Chr (34)). The only thing that worked for me is
Server.HTMLEncode

Which is not very desirable as it Encodes the whole statement and I want to only encode the Double Quote. Ideas?

Regards,

Mo
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 13 June 2007 :  04:13:48  Show Profile
replace(pm.GetItem("BookTitle"),"""","\""")


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.5 seconds. Powered By: Snitz Forums 2000 Version 3.4.07