I was digging through my files when I found this subroutine and I thought, maybe somebody out there might need it. It’s not my original code though (and I forgot where I got it). Anyhow, I just wanted to share it and here it is:
Public Sub ExportToExcel()
Dim table as Datatable = “Query your datatable here”
Dim name as String = “filename”Dim context As HttpContext = HttpContext.Current
context.Response.Clear()
For Each column As DataColumn In table.Columns
context.Response.Write(column.ColumnName & “,”)
Next
context.Response.Write(Environment.NewLine)
For Each row As DataRow In table.Rows
For i As Integer = 0 To table.Columns.Count - 1
context.Response.Write(row(i).ToString().Replace(”,”, String.Empty) & “,”)
Next
context.Response.Write(Environment.NewLine)
Next
context.Response.ContentType = “text/csv”
context.Response.AppendHeader(”Content-Disposition”, “attachment; filename=” & name & “.csv”)
context.Response.[End]()LoadData_Base()
End Sub
Tags: vb .net sample code
A simple timer class written in VB .Net
Imports System.Timers
Public Class TestTimer
Shared _timer As New Timer()
Dim _timerInterval As Integer = 10000 ‘in milliseccondsPublic Sub New()
Initialize()
End SubPublic Sub Initialize()
AddHandler _timer.Elapsed, AddressOf _timer_Elapsed
_timer.Interval = _timerInterval
End SubPublic Sub _timer_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)
‘As long as timer is ‘enabled’ this function will be triggered every time interval set (in this case every 10 seconds)
‘do something here
End SubPublic Sub start()
_timer.Enabled = True
End SubPublic Sub stopTimer()
_timer.Enabled = False
End SubEnd Class
Tags: vb .net sample code
.Net asp .net tutorial asp .net tutorial c# sample code CSS sample script database guide java sample code javascript sample code mssql sample script string reverse in C# t-sql telerik sample code user-defined function vb .net sample code visual studio tutorial
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.