Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generating an Excel Spreadsheet!
Message
From
10/04/2002 17:45:59
 
 
To
10/04/2002 15:23:17
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00643414
Message ID:
00643505
Views:
7
Randy,
Just a guess, but I think the INSERT fails because the empty spreadsheet doesn't have any structure (fieldnames, data types, etc.). Try something like this:
'create a new sheet. Define some columns and data types
objCmd.CommandText = "CREATE TABLE NewSheet (Col1 TEXT, Col2 NUMBER, Col3 DATE)"
'insert some data. You can now refer to the column names
objCmd.CommandText = "INSERT INTO [NewSheet$] (Col1, Col2) VALUES ('Some Text', 123)"
HTH

>I am having a lot difficulty inserting a record into an excel spreadsheet. I am basically using the exact code found on the msdn support webpage. I keep getting the error - Unknown field. I have an empty worksheet and I am trying to insert data into the first cell. I have tried using the fieldname A and A1. I have also tried renaming the first cell and using it in my insert statement, but I keep getting the same error. Can anyone help me with this, please. Below is the code I am using. Thanks for the help.
>
>

>'Establish a connection to the data source.
> Dim sConnectionString As String
> sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=" & sSampleFolder & _
> "Book7.xls;Extended Properties=Excel 8.0;"
> Dim objConn As New System.Data.OleDb.OleDbConnection _
> (sConnectionString)
> objConn.Open()
>
> 'Add a record to the table.
> Dim objCmd As New System.Data.OleDb.OleDbCommand()
> objCmd.Connection = objConn
>
> objCmd.CommandText = "Insert into [Sheet1$] (A)" & _
> " values ('Bill')"
>
> ' In place of A, I have tried A1 and ID after renaming the cell.
> objCmd.ExecuteNonQuery()
>
> 'Close the connection.
> objConn.Close()
><\pre>
Daniel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform