I am trying to create an Excel spreadsheet using the Microsoft.ACE.OLEDB.12.0 provider in vb.net, and I cannot seem to define a field that allows more than 255 characters.
Here is my current code to create the table:
create table [table_name] ([column_1] VarChar)
I understand that VarChar is limited to 255 characters, but I am unable to figure out an alternative that will hold more.
I've tried this:
create table [table_name] ([column_1] LongVarChar)
and got a "Syntax error in field definition" exception.
Similarly, I've tried LongVarWChar, Memo, NText(8000),... with the same results. Any suggestions?
EDIT: Here is my connection string:
"Provider=Microsoft.ACE.OLEDB.12.0;" &
"Data Source=" & destinationFile & ";" &
"Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
EDIT 2: Here is the basic idea of what I'm trying to do
Imports System.Data.OleDb Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dim destinationFile = "c:\users\dell\desktop\test\test_" & Now.ToString("yyyyMMdd_HHmmssfffff") & ".xlsx"
Dim oleDbConnString =
"Provider=Microsoft.ACE.OLEDB.12.0;" &
"Data Source=" & destinationFile & ";" &
"Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
Dim oleDbConn as New OleDbConnection(oleDbConnString)
Dim oleDbComm as New OleDbCommand("create table Sheet1 (column_1 LongText);", oleDbConn)
oleDbConn.Open
oleDbComm.ExecuteNonQuery
oleDbConn.Close
Dim bigText as New StringBuilder()
For i = 0 to 255
bigText.Append(".")
Next
oleDbComm.CommandText = "insert into Sheet1(column_1) values ('" & bigText.ToString & "');"
oleDbConn.Open
oleDbComm.ExecuteNonQuery
oleDbConn.Close
Process.Start(destinationFile)
End Sub
End Class
Exception gets thrown on the last ExecuteNonQuery call in the Button1_Click sub. In place of "LongText", I've tried many different data types, including a bunch that are not valid for an Excel data source using the Ace engine. I've found nothing that allows me to insert a string larger than 255 characters.