出力にフィールド名を表示したいのですが、これを解決する方法がわかりません。誰でも助けてください..
Test.aspx.vb
Private Sub IFexportData()
Try
Dim fileLog, filePath, fileName As String
fileLog = Year(dtDate.Text) & Month(dtDate.Text) & Day(dtDate.Text) & ".log"
filePath = configurationAppSettings.GetValue("ExtractPath", GetType(System.String))
fileName = filePath & "\" & fileLog
Dim IFStorage As New SqlServerStorage(GetType(IFFormat))
Dim cipherUsername, cipherPassword As Byte()
cipherUsername = Encoder.Base64Decode(configurationAppSettings.GetValue("UserID", _
GetType(System.String)))
cipherPassword = Encoder.Base64Decode(configurationAppSettings.GetValue("Password", _
GetType(System.String)))
With IFStorage
'.TransactionMode = 3
.DatabaseName = configurationAppSettings.GetValue("DatabaseName", GetType(System.String))
.ServerName = configurationAppSettings.GetValue("ServerName", GetType(System.String))
.UserName = Dpapi.Decrypt(cipherUsername)
.UserPass = Dpapi.Decrypt(cipherPassword)
End With
IFStorage.SelectSql = "SELECT" & vbCrLf & _
"m.Key, ISNULL(CONVERT(VARCHAR,m.Date,20),'') AS Date," & vbCrLf & _
"ISNULL(m.Loc,'') AS Loc," & vbCrLf & _
"ISNULL(CONVERT(VARCHAR,m.Sched,20),'') AS Sched" & vbCrLf & _
"FROM TAB1 p INNER JOIN" & vbCrLf & _
"TAB2 m ON p.Code = m.Code" & vbCrLf & _
"ORDER BY m.Date, m.Loc, Sched" & vbCrLf
IFStorage.FillRecordCallback = New FillRecordHandler(AddressOf FillIFRecord)
Dim res As IFFormat() = CType(IFStorage.ExtractRecords, IFFormat())
Dim link As New FileDataLink(IFStorage)
link.ExtractToFile(fileName)
Dim file As System.IO.FileInfo = New System.IO.FileInfo(fileName)
If file.Exists Then 'set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End() 'if file does not exist
Else
Response.Write("This file does not exist.")
End If 'nothing in the URL as HTTP GET
Catch ex As Exception
Response.Write("<script language=javascript>alert('" & ex.Message.Replace("'", """") & "');</script>")
End Try
End Sub
Protected Sub FillIFRecord(ByVal rec As Object, ByVal fields() As Object)
Dim record As IFFormat
record = rec
record.Key = fields(0)
record.Date = fields(1)
record.Loc = fields(2)
record.Sched = fields(3)
End Sub
IFFormat.vb
[DelimitedRecord(",")]
Public Class IFFormat
Public Key As String
Public Date As String
[FieldQuoted()] Public Loc As String
Public Sched As String
End Class
私が得たサンプル出力xxxxxxxxxxx.log
:
1896044529,2012-10-01 00:00:00,"ABC",2012-10-01 04:10:00
1896044529,2012-10-01 00:00:00,"DEF",2012-10-01 04:22:00
1896044663,2012-10-01 00:00:00,"GHI",2012-10-01 04:36:00
1896044672,2012-10-01 00:00:00,"JKL",2012-10-01 04:44:00
私が望む出力:
"Key","Date","Loc","Sched"
1896044529,2012-10-01 00:00:00,"ABC",2012-10-01 04:10:00
1896044529,2012-10-01 00:00:00,"DEF",2012-10-01 04:22:00
1896044663,2012-10-01 00:00:00,"GHI",2012-10-01 04:36:00
1896044672,2012-10-01 00:00:00,"JKL",2012-10-01 04:44:00