Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Export to XLS

Export to XLS

Scheduled Pinned Locked Moved Database
databasecsharphelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mosquitooth
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • M mosquitooth

      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

      C Offline
      C Offline
      chinni1
      wrote on last edited by
      #2

      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() :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups