Archive

Posts Tagged ‘DB2’

How to display non-latin characters in ASP Classic

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.

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());
}
return retStr.ToString();
}
return "";
}

Function in ASP to convert from ASCII to Characters:

Function ConvertToChar(byval str)
'delimiters
dim delrows, delitems, delcols
delrows = "___NLINE__"
delcols = "N$XITM_"
delitems = "&"
'********************************
'return string
dim strConverted
'arrays
dim arryRows, arryCols, arryItems
'counters
dim ctrrows, ctrcol, ctritems
'Ubound Var
dim UarryRows,UarryCols,UarryItems
strConverted = ""
dim ichr
'Get the Rows
arryRows = split(str,delrows)
UarryRows = Cint(Ubound(arryRows))
for ctrrows = 0 to UarryRows
'Get Columns
arryCols = split(arryRows(ctrrows),delcols)
UarryCols = Cint(ubound(arryCols))
for ctrCol = 0 to UarryCols
'Get Items
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
case else:
if ichr > 254 then
strConverted = strConverted & Chrw(ichr)
else
strConverted = strConverted & Chr(ichr)
end if
end select
else
strConverted = strConverted & arryItems(ctrItems)
end if
next
'Adds NextItem Attrib
if (ctrCol UarryCols) then strConverted = strConverted & delcols
next
'Adds NextLine Attrib
if (ctrrows UarryRows) then strConverted = strConverted & delrows
next
ConvertToChar = strConverted
End Function

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.

Advertisements
Categories: .NET Development Tags: , ,
%d bloggers like this: