【发布时间】:2016-01-04 17:10:07
【问题描述】:
我有一个我们正在维护的旧版 VB 应用程序。我们做出的设计决定是将某些数据点存储为连接字符串。由于大部分代码已完成,因此此更改是一成不变的。
我正在循环遍历一组值。我正在做的是,为参考表中的每个值查找一个标签。我需要能够在一个标签中显示值。我很难将这些值合并到一个字符串中,然后将其显示在一个标签中。这是我的代码...
If strField = "Expenditures" Then
If InStr(1, strOldValue, ",") > 0 Then
strArray = Split((strOldValue), ",")
For x = 0 To UBound(strArray)
For Each item In strArray
strMessage = DLookUp(1, "Label", "tblText_References", "ID = '" & item & "'
**''''******here I'm trying to save teh value in strMessage, however, at next item, I need it to be added to strMessage in some fashion, with a (,), I'm not sure how to do it. There are anywhere from 2 to 4 ITEMS i might have.**
Next item
Next
End if
End if
【问题讨论】:
-
呃。这太可怕了。不要像这样存储分隔值。它违反了 1NF 并导致无数的痛苦和痛苦。您将不得不使用动态 sql 来解决这个问题,这很可能会让您自己接受 sql 注入。您最好将每个值存储在自己的行中,然后您可以使用连接来检索用户的所有值。
-
检查是否是第一次通过您的循环。如果不是第一次,strMessage = strMessage & "," ...
-
另外,看起来这是 Access VBA。对吗?
-
@barry17 - 由于您提供的 sn-p 非常小,因此很难提供准确的答案。
-
这就是所有需要的代码。我创建了一个名为 strNEWmessage 的新变量。答案是:strNewAnswer=strNewAnswer & "," strMessage.
标签: sql-server string vb6