ここのプロジェクトで、ネストされたループを使用して stringbuilder を使用していますが、append ステートメントは、列の値の 1 つだけから最初の文字の値を切り取っているようです。ここにループがあります
For Each dr As System.Data.DataRow In gridData.Rows
I = X.CreateElement("I")
B.AppendChild(I)
Dim sb As New StringBuilder
sb.Append("|P|")
For Each dc As DataColumn In dr.Table.Columns
''for ticker value, since it's a link, we need to add a character to the beginning of the value otherwise, the 1st character in
''in the ticker gets truncated. This was recommended by the folks at Treegrid. Only for "link" type columns.
''Same goes for hhname. PD 11.11.2010
''Need to replace null values with space as it creates an issue on the UI with cerain browser versions in that the cell borders disappear.
''By placing in a blank space, it resolves any issues. Another recommendation by treegrid.
If dc.ColumnName.ToUpper = "VCHTICKER" OrElse dc.ColumnName.ToUpper = "VCHHHNAME" Or dc.ColumnName.ToUpper = "ACNTNUM" Or dc.ColumnName.ToUpper = "STATEMENTGROUP" Or dc.ColumnName.ToUpper = "VCHSSNUMBER" Or dc.ColumnName.ToUpper = "VCHLINKLABEL" Or dc.ColumnName.ToUpper = "CACCOUNTNUM" Or dc.ColumnName.ToUpper = "VCHSECURITY_SYMBOL" Then
If dc.ColumnName.ToUpper = "CACCOUNTNUM" Or dc.ColumnName.ToUpper = "VCHSECURITY_SYMBOL" Then
sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", dr.Item(dc.ColumnName).ToString).ToString & "|")
Else
sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", "~" & dr.Item(dc.ColumnName).ToString).ToString & "|")
End If
ElseIf dc.ColumnName.ToUpper = "GROUP1" Then
If ((dr.Item("IHHID").ToString.Length > 0) And (dr.Item("IHHID").ToString <> "0")) Then
sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", "~" & dr.Item(dc.ColumnName).ToString).ToString & "|")
Else
sb.Append(NullConvert.ToString(dr.Item(dc.ColumnName)) & "|")
End If
Else
'sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", dr.Item(dc.ColumnName)).ToString & "|")
sb.Append(NullConvert.ToString(dr.Item(dc.ColumnName)) & "|")
End If
Next dc
Dim XMLString As String = sb.ToString.Substring(0, sb.ToString.Length - 1)
Dim descText As XmlText = X.CreateTextNode(sb.ToString)
I.AppendChild(descText)
icount += 1
If icount > Constants.MAX_RECORDS Then
Exit For
End If
Next dr
私が抱えている問題はここにあります。
If dc.ColumnName.ToUpper = "CACCOUNTNUM" Or dc.ColumnName.ToUpper = "VCHSECURITY_SYMBOL" Then
sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", dr.Item(dc.ColumnName).ToString).ToString & "|")
Else
sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", "~" & dr.Item(dc.ColumnName).ToString).ToString & "|")
End If
dr.Item の値が「HSC01234」のように保存されるのではなく、末尾のスペースと先頭文字が削除された「SC01234」として保存されます。このインスタンスでは、値が NULL になることはないため、"~nbsp;" ヒットしません。どんな助けでも大歓迎です。ありがとう、ニックG