~relax~
這是一個悠閒放鬆的部落格,請用輕鬆的心情閱讀文章,在忙碌工作之餘療癒自己的身心。 (最近發現我的文章被複製轉貼且沒有註明出處,本部落格的文章皆為原創,若有引用參考也會註明,如有需求請留言告知,謝謝!)
'DataTable存成CSV檔的程式碼----------------------------------
Dim SavePath As String = "C:\Temp\"
Dim FileName As String = "Test.csv"
Dim FilePath As String = SavePath + FileName
Dim sw As New System.IO.StreamWriter(FilePath , False, System.Text.Encoding.Default)

'寫入欄位名稱
If MyDataTable.Columns.Count > 0 Then
    sw.Write(MyDataTable.Columns.Item(0).ColumnName.ToString)
End If
For i As Integer = 1 To MyDataTable.Columns.Count - 1
    sw.Write("," + MyDataTable.Columns.Item(i).ColumnName.ToString)
Next
sw.Write(sw.NewLine)

'寫入各欄位資料
For i As Integer = 0 To MyDataTable.Rows.Count - 1
    For j As Integer = 0 To MyDataTable.Columns.Count - 1
        If j = 0 Then
            sw.Write(MyDataTable.Rows(i)(j))
        Else
            sw.Write("," + MyDataTable.Rows(i)(j))
        End If
    Next
    sw.Write(sw.NewLine)
Next

sw.Close()

'使用SaveAs.aspx隱藏檔案路徑讓使用者下載
Response.Redirect("SaveAs.aspx?filename=" + FileName)
'SaveAs.aspx.vb Page_Load 內的程式碼--------------------------
Dim SavePath As String = "C:\Temp\"
Dim FileName As String = Request.QueryString("filename").ToString
Dim FilePath As String = SavePath + FileName

'設定表頭並存檔
If System.IO.File.Exists(filep) Then
    With Response
        .ContentType = "application/save-as"
        .AddHeader("content-disposition", "attachment; filename=" & FileName)
        .ContentEncoding = Encoding.UTF8
        .WriteFile(FilePath)
    End With
Else
    Response.Write("no file")
End If
'做成Class方便使用
Public Class ExportCSV
    Function DataTableToCSV(ByVal dt As Data.DataTable, ByVal FileName As String, ByVal SavePath As String) As Boolean
        Dim FilePath As String = SavePath + FileName
        Try
            Dim sw As New System.IO.StreamWriter(FilePath, False, System.Text.Encoding.Default)

            If dt.Columns.Count > 0 Then
                sw.Write(dt.Columns.Item(0).ColumnName.ToString)
            End If
            For i As Integer = 1 To dt.Columns.Count - 1
                sw.Write("," + dt.Columns.Item(i).ColumnName.ToString)
            Next
            sw.Write(sw.NewLine)

            For i As Integer = 0 To dt.Rows.Count - 1
                For j As Integer = 0 To dt.Columns.Count - 1
                    If j = 0 Then
                        sw.Write(dt.Rows(i)(j))
                    Else
                        sw.Write("," + dt.Rows(i)(j))
                    End If
                Next
                sw.Write(sw.NewLine)
            Next
            sw.Close()
        Catch ex As Exception
            'MsgBox(ex.Message)
            Throw ex
        End Try

        If System.IO.File.Exists(FilePath) Then
            Return True
        Else
            Return False
        End If

    End Function
End Class
'存成CSV檔
Dim SavePath As String = "C:\Temp\"
Dim FileName As String = "Test.csv"
Dim epCsv As New ExportCSV
If epCsv.DataTableToCSV(MyDataTable, FileName, SavePath) = True Then
    Response.Redirect("SaveAs.aspx?filename=" + FileName)
End If

伊 發表在 痞客邦 留言(0) 人氣()

有的人參加跨年晚會倒數 來迎接2011年
有的人熬夜看第一道曙光 來迎接2011年
有的人一大早參加新年升旗 來迎接2011年
那你呢?

伊 發表在 痞客邦 留言(0) 人氣()

1.資料在資料庫系統中,通常是指格子內的文字、數字,但單一格子的資料是沒有意義的,以身分證字號為例,必須結合姓名、電話、等..欄位,才形成一個人的資本資料,對資料庫而言,此一基本資料就是紀錄

2.資料經過處理,產生某種特殊意義(提供有用的訊息),就可視為資訊(Infomation),而此一整理的動作,在電腦內就是使用資料庫,其作用就是將原本雜亂無章的資料,經由資料庫的處理,轉化為可以依不同目的,取得的資訊。

3.資料庫系統發展史:集中式處理→主從架構→分散式處理

資料庫架構發展史.gif  

伊 發表在 痞客邦 留言(0) 人氣()

夫妻吵架的藝術 .千萬不要贏有道理

朋友間 也是一樣

贏得談話 失去友誼

伊 發表在 痞客邦 留言(0) 人氣()

加入參考 => COM => Microsoft Excel 10.0 Object Library 後,發生下列錯誤:
CLSID {00024500-0000-0000-C000-000000000046} 的元件擷取 COM Class Factory 失敗: 80070005

解決辦法:
1.執行 dcomcnfg.exe(元件服務)

伊 發表在 痞客邦 留言(0) 人氣()


function getPathName()
{
    if(window.location.protocol =="file:")
    {

文章標籤

伊 發表在 痞客邦 留言(0) 人氣()

<script language="javascript">

var test =

{

max:function(a,b){ return a>b?a:b; },

min:function(a,b){ return a<b?a:b; }

文章標籤

伊 發表在 痞客邦 留言(0) 人氣()

GROUP BY應用,計算平均成績:
select 學號, avg(成績) as 平均成績
from 成績表
group by 學號
order by avg(成績) desc

文章標籤

伊 發表在 痞客邦 留言(0) 人氣()