On Wed, 16 Feb 2005 16:55:29 -0500, "Cathy" <cm******@co.dutchess.ny.us> wrote:
¤ Hi All,
¤
¤ Can anyone tell me how to create an Excel (.xls) file from a VB.Net app? I
¤ have a SQL Server database that contains a table with the data I want to
¤ export. How do I create the file? Any code samples?
See if the following works for you:
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Orders.xls;Extended Properties=""Excel 8.0;HDR=NO"""
Dim ExcelConnection As New System.Data.OleDb.OleDbConnection(ConnectionString )
ExcelConnection.Open()
Dim ExcelCommand As System.Data.OleDb.OleDbCommand = ExcelConnection.CreateCommand()
ExcelCommand.CommandText = "SELECT * INTO [Orders] FROM [Orders] IN '' [ODBC;Driver={SQL
Server};Server=(local);Database=Northwind;Trusted_ Connection=yes];"
ExcelCommand.CommandType = CommandType.Text
ExcelCommand.ExecuteNonQuery()
ExcelConnection.Close()
Paul ~~~
pc******@ameritech.net
Microsoft MVP (Visual Basic)