473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Error Exporting to Excel

I get the error message:

"Exception Details: System.Data.OleDb.OleDbException: Table 'Hank' already
exists."

when executing the following code:

Dim AccessConn As New System.Data.OleDb.OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:\My Documents\db1.mdb")

AccessConn.Open()

'New sheet in Workbook
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT *
INTO [Excel 8.0; DATABASE=c:\My Documents\Book11.xls; HDR=NO;].[Hank] FROM
myTable", AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()

(Code is provided by Paul Clement, 9-13-2005)

It's interesting that the data from the table is exported to the newly
created workbook, "Book11", and the data resdies in the worksheet "Hank", but
the error message "Table 'Hank' already exists" comes up anyway.

What is the best way to get rid of the error as my ASP.Net application bombs?

Thank you, Mark

Nov 21 '05 #1
3 1329
Exceltable
Nov 21 '05 #2
Mark,

Although I am not sure, you can use this of course only one time.

That is in my opinon not likely because every client can do this again and
again, be aware that you create this access table on the server.

I hope this helps,

Cor
Nov 21 '05 #3
On Sun, 30 Oct 2005 20:01:03 -0800, "Mark" <Ma**@discussions.microsoft.com> wrote:

¤ I get the error message:
¤
¤ "Exception Details: System.Data.OleDb.OleDbException: Table 'Hank' already
¤ exists."
¤
¤ when executing the following code:
¤
¤ Dim AccessConn As New System.Data.OleDb.OleDbConnection
¤ ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:\My Documents\db1.mdb")
¤
¤ AccessConn.Open()
¤
¤ 'New sheet in Workbook
¤ Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT *
¤ INTO [Excel 8.0; DATABASE=c:\My Documents\Book11.xls; HDR=NO;].[Hank] FROM
¤ myTable", AccessConn)
¤
¤ AccessCommand.ExecuteNonQuery()
¤ AccessConn.Close()
¤
¤ (Code is provided by Paul Clement, 9-13-2005)
¤
¤ It's interesting that the data from the table is exported to the newly
¤ created workbook, "Book11", and the data resdies in the worksheet "Hank", but
¤ the error message "Table 'Hank' already exists" comes up anyway.
¤
¤ What is the best way to get rid of the error as my ASP.Net application bombs?
¤
¤ Thank you, Mark

The SQL statement you are using will *always* attempt to create a new Table (Worksheet in Excel). If
you're adding data to an existing table you should be using an Insert statement instead of Select
Into.

If you're saying that the Table 'Hank' currently does not exist then I would have to see the
Workbook in order to determine what might be happening.
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
2
by: G | last post by:
When I export data from access to excel by with "export" or "Analyze with" I seem to loose parts of some fields (long text strings). Is there a way to export it all to excel? Thanks G
3
by: Andres Romero | last post by:
I have a button in my html page for exporting to excel files using the RenderControl function. When the table generated is small in rows size it works fine, but when there are much more rows (more...
1
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
2
by: accessvbanewbie | last post by:
I keep getting an error stating OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET. This error just recently began to happen. I am exporting some records to excel into a preformatted report. The...
3
by: Tempalli | last post by:
I am exporting the data from ms access to excel where the error displays as Run-time error -2147467259(800004005) Method 'Copyfromrecordset' of object 'Range' faild. ...
3
by: nandithadevaraj | last post by:
When exporting a report to excel, is it possible to keep the properties around numeric values? More specifically - when exporting a report into excel, all of the numbers in a currency column are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.