Solved

StringBuilder in ASP.net vs Classic ASP

Posted on 2015-02-05
5
196 Views
Last Modified: 2015-02-17
Hello

I'm attempting to write a routine that loops trough all the fields from one column of a database and write out a XML
I got a friend who helped me write some pseudo-code in asp.net, but I can't find how to run this in classic asp.

Any help/suggestions? here is the code:
 
Sub PrepareDataForQFE()
Dim strXML as StringBuilder
{You can set up the XML as a string builder that you manually create or as an XML document – your choice, but for this example, a simple string builder can work}
 
Dim dtTable as DataTable
dtTable = {your query results – obviously you have to run your query}
 
Dim drRow as DataRow
 
For Each drRow in dtTable
     Dim dcCol as DataColumn
 
     For Each dcCol in drRow
           strXML.Add(WriteXML(drCol.ColumnName, drCol.{Value}, {Attributes}))
     Next
Next
 
Result = QFEBridge.CallQuik(FormIDList, strXML.ToString, etc.)
 
End Sub
 
Function WriteXML(strColumnName, strValue, blnReadOnly, strFormat, etc.)
     {This function would write out the field part of the XML}
End Function
0
Comment
Question by:amucinobluedot
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 334 total points
ID: 40592321
As there is no stringbuilder in classic asp you need to use a string

Replace these lines

dim strxml as stringbuilder
with
Dim xmlstr as string

and

 strXML.Add(WriteXML(drCol.ColumnName, drCol.{Value}, {Attributes}))
with
 strxml = strxml & WriteXML(drCol.ColumnName, drCol.{Value}, {Attributes})

finally

Result = QFEBridge.CallQuik(FormIDList, strXML.ToString, etc.)
with
Result = QFEBridge.CallQuik(FormIDList, strXML, etc.)
0
 

Author Comment

by:amucinobluedot
ID: 40592549
Thank you, This would work for all the values? I have 200 fields on the database and some are extensive (for example, addresses).

Would this hold?
0
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 334 total points
ID: 40592648
As long as the rest of the code supplied is correct, all I have done is replace the stringbuilder in your supplied code with the correct string variable commands, i.e using & to append strings as opposed to the stringbuilder.add method.
0
 

Author Comment

by:amucinobluedot
ID: 40592756
I found some weird mistakes... looks like classic ASP does not accept the "as string"

Microsoft VBScript compilation error '800a0401'
Expected end of statement
/......../page.asp, line 297
Dim strXML As String
-----------------^


Fixed it by removing all the "as", the code ended as follows:

Sub PrepareDataForQFE()
Dim strXML

Dim dtTable
dtTable = rs_usermap

Dim drRow

For Each drRow in dtTable
     Dim dcCol

     For Each dcCol in drRow
           strxml = strxml & WriteXML(drCol.ColumnName, drCol.Fields.Item("QFField"), "&")
     Next
Next
Result = QFEBridge.CallQuik(FormIDList, strXML)
End Sub


Function WriteXML(strColumnName, strValue, blnReadOnly, strFormat)
End Function
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 166 total points
ID: 40593962
as you discovered, there are no data types in classic asp, that's why the statement

dim strXML as string

failed. all variables declared in classic asp are variants, meaning they can be whatever data type you want. you'll also find there are no DataTables in classic asp, instead you'll use a recordset, since you're getting data from a database. so, assuming your recordset has data in it, your code would look like:

Sub PrepareDataForQFE()
Dim strXML, rsData
 
set rs.Execute( "select data from table where conditions = true" )
 
if not rs.BOF and not rs.EOF then    '-- data has been returned 
     for each row in rsData
         for each col in row.Fields
             strXML = strXML & WriteXML( col.Value )
          next
    next
end if 

Result = QFEBridge.CallQuik(FormIDList, strXML.ToString, etc.)
 
End Sub

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now