473,394 Members | 1,951 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,394 software developers and data experts.

Exporting data to excel not working.....

Here is the code.

Dim conExcel As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & ExcelPath & ";Extended Properties=""Excel 8.0;HDR=NO;"""
Dim cmdOLE As OleDb.OleDbCommand
Dim conOLE As OleDb.OleDbConnection
Dim strOLE As String
cmdOLE = New OleDb.OleDbCommand
conOLE = New OleDb.OleDbConnection(conExcel)
conOLE.Open()
With cmdOLE
.CommandText = "INSERT INTO [InvoiceAgingByCompany$] (F1,
F2) VALUES('HI','by')"
.CommandType = CommandType.Text
.Connection = conOLE
.ExecuteNonQuery()
End With
I'm trying to insert into a blank sheet and the sheet name is correct.
I read somewhere that if you specify "HDR=NO" in the connection string
it would automatically name your columns "F1" , "F2" and so on.
The error I get is "The INSERT INTO statement contains the following
unknown field name: 'F2'. Make sure you have typed the name correctly,

and try the operation again."
If I remove the "F2" field and value the statement completes just fine.

Any ideas would be greatly appreciated.

Dec 19 '06 #1
3 1869
"Izzy" <is************@gmail.comwrote in news:1166564570.886639.286220
@a3g2000cwd.googlegroups.com:
Any ideas would be greatly appreciated.
I usually export to CSV - much more compatible and easier to do :-)

Take a look at FileHelpers project on SourceForge.
Dec 20 '06 #2
see

http://www.kjmsolutions.com/datasetarray.htm
Izzy wrote:
Here is the code.

Dim conExcel As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & ExcelPath & ";Extended Properties=""Excel 8.0;HDR=NO;"""
Dim cmdOLE As OleDb.OleDbCommand
Dim conOLE As OleDb.OleDbConnection
Dim strOLE As String
cmdOLE = New OleDb.OleDbCommand
conOLE = New OleDb.OleDbConnection(conExcel)
conOLE.Open()
With cmdOLE
.CommandText = "INSERT INTO [InvoiceAgingByCompany$] (F1,
F2) VALUES('HI','by')"
.CommandType = CommandType.Text
.Connection = conOLE
.ExecuteNonQuery()
End With
I'm trying to insert into a blank sheet and the sheet name is correct.
I read somewhere that if you specify "HDR=NO" in the connection string
it would automatically name your columns "F1" , "F2" and so on.
The error I get is "The INSERT INTO statement contains the following
unknown field name: 'F2'. Make sure you have typed the name correctly,

and try the operation again."
If I remove the "F2" field and value the statement completes just fine.

Any ideas would be greatly appreciated.
Dec 20 '06 #3
Thank you Scorpion, that will work great.

Spam Catcher - I usually write to CSV also when a power user will be
manipulating the data. In this case however it needs to be
pre-formatted. Thanks for the response.

scorpion53061 wrote:
see

http://www.kjmsolutions.com/datasetarray.htm
Izzy wrote:
Here is the code.

Dim conExcel As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & ExcelPath & ";Extended Properties=""Excel 8.0;HDR=NO;"""
Dim cmdOLE As OleDb.OleDbCommand
Dim conOLE As OleDb.OleDbConnection
Dim strOLE As String
cmdOLE = New OleDb.OleDbCommand
conOLE = New OleDb.OleDbConnection(conExcel)
conOLE.Open()
With cmdOLE
.CommandText = "INSERT INTO [InvoiceAgingByCompany$] (F1,
F2) VALUES('HI','by')"
.CommandType = CommandType.Text
.Connection = conOLE
.ExecuteNonQuery()
End With
I'm trying to insert into a blank sheet and the sheet name is correct.
I read somewhere that if you specify "HDR=NO" in the connection string
it would automatically name your columns "F1" , "F2" and so on.
The error I get is "The INSERT INTO statement contains the following
unknown field name: 'F2'. Make sure you have typed the name correctly,

and try the operation again."
If I remove the "F2" field and value the statement completes just fine.

Any ideas would be greatly appreciated.
Dec 20 '06 #4

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

Similar topics

3
by: Chris | last post by:
Could someone please provide me an effective means of exporting data from a data set (or data grid) to Excel?
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: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get...
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...
7
by: semijoyful | last post by:
OS: Win XP SP2 Access version: 2003 Excel version: 2003 I am new at this, as I am sure you have gathered from this post title:) I am working on a form where users can input data in Access and...
3
by: jennwilson | last post by:
Access 2000 - I have developed a database that houses patient information. The patient information must be sent in an excel file to another company department. I know how to export my data to Excel...
2
by: JimmyKoolPantz | last post by:
We purchased som software for encoding a barcode. We want to automate the process of converting a number to a readable barcode. However, I am having a few issues. The file that the barcode...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.