我正在使用Windows应用程序。我从我的sql数据库中获取值,然后写入一个.txt文件。我有一个这样的代码:
sql = "select * from " & strtablename
cmd = New SqlCeCommand(sql, CONN)
dr = cmd.ExecuteReader()
ListBox1.Items.Add("Extracting " & strfilename)
ListBox1.Refresh()
While (dr.Read())
sw = New StreamWriter(hht_Memory & "\Export\" & strfilename & ".txt", True)
prcount = 0
fvalues = ""
For I = 0 To dr.FieldCount - 1
If fvalues = "" Then
fvalues = IIf(IsDBNull(dr(I)), "", dr(I))
fvalues = Trim(Replace(fvalues, "'", ""))
Else
fvalues = fvalues & ", "
fvalues = fvalues & IIf(IsDBNull(dr(I)), "", dr(I))
fvalues = Trim(Replace(fvalues, "'", ""))
End If
Next I
sw.WriteLine(fvalues)
prcount = prcount + 1
sw.Close()
这是写入文本文件。但是由comma.i分隔的每个值都希望通过 | 分隔每个值。
我必须在代码中做出哪些更改?
答案 0 :(得分:1)
这一行:
fvalues = fvalues & ", "
应更改为:
fvalues = fvalues & "| "