I was ask to create COM+ that will return data from DB2 to Classic ASP that has multi-language support.
At first, it was really a headache on how I can accomplish this project. I've try to just passed the data comming from DB2 directly to ASP but it was totally garbage.I get data from DB2 using Dataset and I loop each rows in the dataset to construct a string, since string datatype is compatible with Classic ASP, My delimiter per row is "___NLINE__" and per column is
"N$XITM_". Also in order to connect to DB2, I used Ritmo Driver for iSeries, its a third-party driver that supports .NET.
Well the solution is seems simple, I connect to DB2 server passed the query and then convert the result to Ascii Codes, I set a delimiter for every row, every item, and every letters from COM+ and pass it to ASP then convert again to characters by using spit() , Chr & ChrW function to convert to character since the charset and code page is already declared.
C# Code for converting to ASCII - delimited by & per character:
public static string Chr(string str)
if (str.Length > 0)
StringBuilder retStr = new StringBuilder();
char arrychr = str.ToCharArray();
foreach (char chr in arrychr)
int asciicode = (int)chr;
retStr.Append("&" + asciicode.ToString());
Function in ASP to convert from ASCII to Characters:
Function ConvertToChar(byval str)
dim delrows, delitems, delcols
delrows = "___NLINE__"
delcols = "N$XITM_"
delitems = "&"
dim arryRows, arryCols, arryItems
dim ctrrows, ctrcol, ctritems
strConverted = ""
'Get the Rows
arryRows = split(str,delrows)
UarryRows = Cint(Ubound(arryRows))
for ctrrows = 0 to UarryRows
arryCols = split(arryRows(ctrrows),delcols)
UarryCols = Cint(ubound(arryCols))
for ctrCol = 0 to UarryCols
arryItems = split(arryCols(ctrCol),delitems)
UarryItems = Cint(UBound(arryItems))
for ctrItems = 0 to UarryItems
'checks if Item is ASCII Code
if len(arryItems(ctrItems)) > 1 then
ichr = cLng(arryItems(ctrItems))
select case ichr
case 219,254,221: 'this characters are whitespace
if ichr > 254 then
strConverted = strConverted & Chrw(ichr)
strConverted = strConverted & Chr(ichr)
strConverted = strConverted & arryItems(ctrItems)
'Adds NextItem Attrib
if (ctrCol <> UarryCols) then strConverted = strConverted & delcols
'Adds NextLine Attrib
if (ctrrows <> UarryRows) then strConverted = strConverted & delrows
ConvertToChar = strConverted