excel help give OleDbException Syntax error in INSERT INTO statement


Author
Message
Jocelyn Dagrain
Jocelyn Dagrain
StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)StrataFrame Novice (68 reputation)
Group: Forum Members
Posts: 20, Visits: 127
Bonjour when I try to export using the excel helper I recieved this error message

OleDbException
  Syntax error in INSERT INTO statement.

Source     : Microsoft JET Database Engine

NB. the excel file is created but with only the header

Thank you

Replies
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I looked at the ExportToExcel_AddRow method in the source code. It uses a StringBuilder to put together the syntax involved in the create row method. It is basically a SQL INSERT INTO command. The column names are surrounded with brackets, so hopefully, that would take care of that problem; however, there may be an issue with invalid string data within the business object. Here is the syntax for a string field:



createRow.Append("'" + bo.CurrentRow[col.ColumnName].ToString().Replace("'","") + "'");



createRow is the StringBuilder object. Maybe the Replace method should read: .Replace("'", "''"). Not sure how to solve the problem. Check your string data in the business object and see if anything stands out.



Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Peering into the code a little more, I recognized something quite interesting. The only column types handled by the export are int, long, datetime and string. If there is anything else in that business object outside of those types, then they are considered strings. You may have to excluded those BLOB-type columns from your export.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search