-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: spprivate
Message 2 in Discussion
Hi Srivats Here is a piece of code where in you can write to excel using the file
stream I was using this to open a MS project file and put the contents to excel.You
can similarly do for other databases.Another way of doing this is using the excel
automation object.
Dim i As Integer
Dim strLine As String, filePath, fileName, fileExcel, link
Dim objFileStream As FileStream
Dim objStreamWriter As StreamWriter
Dim nRandom As Random = New Random(DateTime.Now.Millisecond)
Dim fs As Object, myFile As Object
Dim oConn As OleDbConnection
Dim cmd As OleDbCommand
Dim Constring As String
Dim reader As OleDbDataReader
oConn = New OleDbConnection("Provider=Microsoft.Project.OLEDB.10.0;Project
Name=c:\software.mpp")
oConn.Open()
cmd = New OleDbCommand("SELECT TaskID, TaskName FROM Tasks")
cmd.Connection = oConn
reader = cmd.ExecuteReader(CommandBehavior.Default)
'Creating a file name.
fileExcel = "t" & nRandom.Next().ToString() & ".xls"
filePath = "C:"
fileName = filePath & "\" & fileExcel
objFileStream = New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)
objStreamWriter = New StreamWriter(objFileStream)
'Enumerate the field names and records that are used to build the file.
For i = 0 To reader.FieldCount - 1
strLine = strLine & reader.GetName(i).ToString & Chr(9)
Next
'Write the field name information to file.
objStreamWriter.WriteLine(strLine)
strLine = ""
'Traverse the database that is used to populate the file.
While reader.Read()
For i = 0 To reader.FieldCount - 1
strLine = strLine & reader.GetValue(i) & Chr(9)
Next
objStreamWriter.WriteLine(strLine)
strLine = ""
End While
reader.Close()
oConn.Close()
objStreamWriter.Close()
objFileStream.Close()
Response.Write("A File in the name" & fileExcel & "in the path" & filePath & " has
been created")
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]