Private Sub Export2Excel(ByVal filename As String, ByVal data As DataSet)
Dim grid As New System.Web.UI.WebControls.GridView()
grid.HeaderStyle.Font.Bold = True
grid.Font.Size = 8
grid.DataSource = data
grid.DataMember = data.Tables(0).TableName
grid.DataBind()
Using sw As New StreamWriter(filename)
Using hw As New HtmlTextWriter(sw)
grid.RenderControl(hw)
End Using
End Using
MsgBox(filename)
End Sub
Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkbtnExport.Click
connectODB()
Dim da As SqlDataAdapter
Dim ds As DataSet = New DataSet
If ckbAll.Checked = True Then
strSQL = "SELECT * FROM MachineList"
ElseIf ckbTag.Checked = True AndAlso txtTag.Text = " " Then
MsgBox("Plese Enter Tag No")
ElseIf ckbMN.Checked = True AndAlso ckbModel.Checked = True AndAlso ckbBuil.Checked = True AndAlso ckbF.Checked = True Then
strSQL = "SELECT * FROM MachineList WHERE MachineName = '" & cbxMN.Text & "'And Model = '" & cbxmodel.Text & "' And Building = '" & cbxBuil.Text & "' And Floor = '" & cbxF.Text & "'"
ElseIf ckbProcess.Checked = True AndAlso ckbLine.Checked = True AndAlso ckbMN.Checked = True Then
strSQL = "SELECT * FROM MachineList WHERE Process = '" & cbxProcess.Text & "' And Line = '" & cbxLine.Text & "' And MachineName = '" & cbxMN.Text & "'"
End If
da = New SqlDataAdapter(strSQL, conn)
da.Fill(ds)
Dim filename As String
filename = "C:\\" 'จะให้ผู้ใช้เลือกที่จัดเก็บเองต้องใช้ยังไงอ่าคะ
filename &= InputBox("Input Filename : ")
filename &= ".xls"
Export2Excel(filename, ds)
conn.Close()
End Sub