[英]Database values to array and join with VBscript
數據庫中的值看起來像10000000,10000001,10000002。 現在,我已將值保存到字符串(ID),並且想要為其分配一個新值並進行連接,以便它顯示為0a,1a,2b。
Dim LineOfText
Dim i
Dim aryTextFile(12)
if ID.contains("10000000") then
aryTextFile(9) = "0a"
end if
if ID.contains("10000002") then
aryTextFile(10) = "1a"
end if
if ID.contains("10000001") then
aryTextFile(11) = "2b"
end if
LineOfText = String.Join(",", aryTextFile)
嘗試此操作會給我錯誤Microsoft VBScript運行時錯誤'800a01a8'
所需對象:“ 10000001,10000002”
那我在做什么錯?
在考慮了一些之后,也許我沒有將值正確地轉換為字符串。
strSQL = "SELECT ID from table where hdnID like 3696 "
set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, cn, 0, 1
Dim ID
ID = objRec("ID")
我在C#中有此功能,但需要等效的vbscript C#代碼是
string[] Otherspace = new string[] { 1a, 2b, 3c };
string txaNotes = String.Join(", ", Otherspace.Where(q => !string.IsNullOrEmpty(q)));
嘗試這個:
LineOfText = join(aryTextFile, ",")
您可以使用.Net導入來構建數組,然后將其加入。
如何實現此目的的示例:
Dim DataList, ID
ID = "10000000 foo 10000002 bar"
Set DataList = CreateObject("System.Collections.ArrayList")
If instr(ID, "10000000") Then DataList.Add "0a"
If instr(ID, "10000001") Then DataList.Add "1a"
If instr(ID, "10000002") Then DataList.Add "2b"
LineOfText = join(DataList.ToArray, ", ")
' LineOfText will have value "0a, 2b"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.