Click here to Skip to main content
15,914,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a program that output a report in excel file. I use OLEDB Connection in adding rows.

VB
Try
    Dim MyConnection As System.Data.OleDb.OleDbConnection
    Dim myCommand As New System.Data.OleDb.OleDbCommand
    Dim sql As String

    MyConnection = New System.Data.OleDb.OleDbConnection _
    ("provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + _
    "'c:\test.xls';Extended Properties=Excel 8.0;")

    MyConnection.Open()
    myCommand.Connection = MyConnection
    sql = "Insert into [Sheet1$] (id,name) values('5','e')"
    myCommand.CommandText = sql
    myCommand.ExecuteNonQuery()
    MyConnection.Close()
Catch ex As Exception
    MsgBox(ex.ToString)
End Try
MsgBox("Row Added ")


Found this in http://www.java-samples.com/showtutorial.php?tutorialid=1051[^]

My problem is before I add row in that excel file I must have a header as field names.
'THIS IS THE CONTENT IN EXCEL FILE
id | name


How can I add row in excel file without that header.

Thanks...
Posted

THe problem is with your connection string. Go to ConnectionStrings.com[^] and you'll find a ton of them, including samples on supporting sheets with header rows.
 
Share this answer
 
This could be helpful: inserting data in excel[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900