473,409 Members | 2,004 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,409 software developers and data experts.

Proper SQL syntax to insert a row to Excel without a header row

24
I am trying to insert to an Excel 12 spreadsheet through VB/ADO .Net 2.0

Here's my connection string
Expand|Select|Wrap|Line Numbers
  1. Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Book1.xls;Extended Properties=""Excel 12.0;HDR=NO"""
  2.  
This works fine if i have HDR=YES and respectfully named columns in the header row
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [Sheet1$](ColA,ColB,ColC,ColD) VALUES('A','B','C','D')
  2.  
But I want to be able to insert without a header row by just specifying the embedded Excel column names A,B,C etc

Help would be very much appreciated


working code with header:
Expand|Select|Wrap|Line Numbers
  1.         Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Book1.xls;Extended Properties=""Excel 12.0;HDR=YES"""
  2.         Dim factory As DbProviderFactory = DbProviderFactories.GetFactory("System.Data.OleDb")
  3.         Dim Command As DbCommand = factory.CreateCommand
  4.         Dim Connection As DbConnection = factory.CreateConnection()
  5.  
  6.  
  7.         Connection.ConnectionString = connectionString
  8.  
  9.        Command.CommandText = "INSERT INTO [Sheet1$](ColA,ColB,ColC,ColD) VALUES('A','B','C','D')"
  10.  
  11.             Connection.Open()
  12.             Command.Connection = Connection
  13.             Command.ExecuteNonQuery()
  14.  
  15.  
Jun 14 '11 #1
0 1300

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kevin | last post by:
I am currently importing data into Access 2002 from 3 Sybase ASA 7.0 databases over a network. At this time I am using a ODBC System DSN connection using the proper ASA 7 driver. I would like to...
0
by: ganeshboom | last post by:
hello to every one ,i am doing one project,i want to insert excel sheet in richtextbox of vb.net,or i want to insert any object into richtextbox of vb.net,my project is like a wordpad,in wordpad one...
4
by: ajlu | last post by:
Hi all, Is it possible to compile a c++ program without header, if possible please let me know in detail... ***ajlu***
1
by: dmkeith2 | last post by:
This is probably easy to do but I can't find it in the groups. How do I paste into an excel document without the MS Access headers? I just want to paste the data. Thanks
1
by: steveKC | last post by:
Hi, Anyone know how to extarct data from Oracle to excel without the header using vb.net? Below is my coding: Dim rst As ADODB.Recordset cn = New ADODB.Connection
3
by: monadel | last post by:
Hi Guys, Can anyone help me with this problem please. I cant export a queries that I wrote in vb script into excel with Header according into the queries that I wrote. I can export the data but...
9
by: svdoerga | last post by:
I am wondering how you can change the fontcolor in the header or footer in VBA when exporting to excel. I need some text in red. I found the ms page with the codes here. It's saying the formatting is...
1
by: finish77 | last post by:
Hello' I'm trying to apply font color in Excel's header. I found out (using a macro) that "KFF0000" represents the color red, but in my application the user can choose what color he wants for the...
11
by: tvnaidu | last post by:
I´m trying to display certain page without header image or footer image (I need to reload only variable values). Is there any way of disabling them in html code?, I am using refresh now, it reloads...
1
by: Amy Badgett | last post by:
Could anyone give me the proper syntax for executing a SQL Update Query in VBA in an on_click event? Maybe like a step-by-step explanation?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.