21 July 2008

excel from sql

hm... interesting!!
i know a way to read excel from sql query.
this is how to do it...

first of all:
reconfigure 'Ad Hoc Distributed Queries' to enable position by run this query:

sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure

to check or view the value of configuration run this query : "sp_configure" (find 'Ad Hoc Distributed Queries')


second:
SET IDENTITY_INSERT [table] ON 

the main formula is :
select * from OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0; Database=[FOLDER LOKASI DI SERVER]\FileExcelnya.xls', 'select * from [Sheet1$]')
attention!! the first row become the field name on sql

dont forget to
SET IDENTITY_INSERT [table] OFF


*condition: only read excel version 97-2003

18 July 2008

email in .net

Imports System.Web.Mail

#Region "Email"
Public Function SendEmail(ByVal mpSENDTO As String, Optional ByVal mpCC As String = "", Optional ByVal mpBCC As String = "", Optional ByVal mpMESSAGEFROM As String = "", Optional ByVal mpSUBJECT As String = "", Optional ByVal mpBODY As String = "", Optional ByVal mpATTACHMENT As String = "") As Boolean
Dim mlMESSAGE As New MailMessage()
Try
mlMESSAGE.To = mpSENDTO
mlMESSAGE.Cc = mpCC
mlMESSAGE.Bcc = mpBCC
mlMESSAGE.Subject = mpSUBJECT
mlMESSAGE.Body = mpBODY
mlMESSAGE.From = mpMESSAGEFROM
mlMESSAGE.BodyFormat = MailFormat.Html
SmtpMail.Send(mlMESSAGE)
Return True
Catch ex As Exception
Return False
End Try
End Function
#End Region

Twiit.. Twiit... Gulp