vb使⽤StreamWriter书写流写出数据并⽣成⽂件
sql = "Select case when date ='' then '0'else CONVERT(varchar(100), date, 101) end as date,case when ad ='' then '0'else CONVERT(varchar(100), ad, 101) end as ad,event1,type1,code from EventData where ip='" + UserIP + "' order by code,ev Dim table As DataTable = gData.GetDataTable(sql, SqlConnect) '將所有的查詢結果放⼊臨時表中,在查詢臨時表內容
Dim count = table.Rows.Count
If count = 0Then
MessageBox.Show("no data.")
Exit Sub
End If
Dim sw As StreamWriter = File.CreateText(TextBox1.Text & "\" & "Events.csv") '在桌⾯創建⽂件Events.csv
Dim c As String = ""
For i As Integer = 0To count
writeline用什么替代
If i = 0Then'header
sw.WriteLine("E.CODE,E.TYPE,E.EVENT,E.AD,E.DONE") '標題
Else'data
For j As Integer = 0To4'⼀共5列
If j = 0Then
c = table.Rows(i - 1).Item(j)
Else
c = table.Rows(i - 1).Item(j) & "," & c '對字段進⾏拼接
End If
Next
sw.WriteLine(c)
c = ""'將C清空
End If
Next
sw.Flush()
sw.Close() '新建⽂件將原有的內容覆蓋

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。