Export to XLS
-
Hi I run the following SQL- statement in my VB.NET application to export the results of a query to Excel: g.CommandText = "SELECT * INTO [Excel 8.0;DATABASE=C:\test.xls;HDR=NO;].Table1 FROM [MyTable] WHERE... 'g is a valid OleDbCommand object This statement fails, if the xls- file already exists. I've heard that the INSERT INTO statement could deal with this - could anyone provide me some SQL- string that does the trick?? Thanks a lot! Can anyone help me? Gordon
-
Hi I run the following SQL- statement in my VB.NET application to export the results of a query to Excel: g.CommandText = "SELECT * INTO [Excel 8.0;DATABASE=C:\test.xls;HDR=NO;].Table1 FROM [MyTable] WHERE... 'g is a valid OleDbCommand object This statement fails, if the xls- file already exists. I've heard that the INSERT INTO statement could deal with this - could anyone provide me some SQL- string that does the trick?? Thanks a lot! Can anyone help me? Gordon
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() :)