Solved

StringBuilder in ASP.net vs Classic ASP

Posted on 2015-02-05
5
215 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 33

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get hold of longitude and latitude in iframe string 11 46
VB.NET Repostiory Pattern 7 37
Help with query 3 25
Send SMS from VB via Sierra Wireless Modem 2 21
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

773 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