Grails: save parsed csv data to database - csv

I have successfully parsed by csv using grails plugin. Now the output looks like:
This is how i parsed the csvFile. I need to save this csv contents to database.How can i do this?
def upload = {
def f = request.getFile('filecsv')
if (f.empty) {
flash.message = 'file cannot be empty'
render(view: 'uploadForm')
return
} else {
def file = request.getFile('filecsv')
def singlerow = file.inputStream.toCsvReader(['charset': 'UTF-8', 'separatorChar': '|']).eachLine{
line ->
println "The data are"+line
}
}
}
Output looks like
The data are[test, 2017-08-21, , , 2017-08-21, 100, 8668a73e55e0824c130337d49f0fc746, , Annual, , , , , , , , , , , , , , , , , , , , , test, 1111, test, test, 1901-03-13, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , asd/asd/sad/incentive/20170906/09062017.csv, 2017-09-06, , 4.7, 30430001]
The data are[test, 2017-10-07, , , 2017-08-07, 100, asdasdasdasd, , An, , , , , , , , , , , , , , , , , , , , , test, 1111, test, test, 1900-02-15, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , stat/test/test/incentive/20170906/ 09072017.csv, 2017-09-06, , 4.7, 30430001]
My domain class:
class Data {
String data1
Date data12
Date data13
Date data14
Date data15
String data16
String data17
String data18
String data19
String data110
String data111
String data112
String data113
String data114
String data115
String data115
String data116
String data117
String data118
String data119
String data120
_____________
__________
___________
}
How can i save this to database of this domain class.

Without knowing other details, the easiest way to save such domain instances I can think of is:
static dates = [ 11, 12, 13, 14 ] // positions of fields to be converted to Date
def upload = {
//...
file.inputStream.toCsvReader(['charset': 'UTF-8', 'separatorChar': '|']).eachLine{ line ->
def map = [:]
line.eachWithWithIndex{ d, ix ->
// if( d ) map[ "data${ix+1}" ] = dates.contains( ix ) ? Date.parse( 'yyyy-MM-dd', d ) : d
if( d ) map[ "data${ix+1}" ] = d // if you need no date conversion
}
Data data = new Data( map )
if( !data.save() ) log.warn "save failed: $data.errors"
}
}

Related

Google Apps Script - Import Contacts from CSV with trigger - TypeError: Cannot read property 'getRange' of null

wann Import Contacts from a CSV File with Google Apps Script
the CSV File is stored on Google Drive.
I found this example:
But did not work for me:
function importCSVFromGoogleDrive() {
var file = DriveApp.getFilesByName('file.csv').next();
Logger.log(file.getSize());
Logger.log(file.getName());
Logger.log(file.getDateCreated());
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
got this error:
14:45:50
Hinweis
Ausführung begonnen
14:45:51
Info
1624.0
14:45:51
Info
file.csv
14:45:51
Info
Fri Sep 17 11:51:35 GMT+02:00 2021
14:45:51
Fehler
TypeError: Cannot read property 'getRange' of null
importCSVFromGoogleDrive
# import.gs:9
How to fix this ?
If i set this line:
Logger.log(Utilities.parseCsv(file.getBlob().getDataAsString()));
I can see the content of the CSV file.
15:27:26
Hinweis
Ausführung begonnen
15:27:26
Info
1624.0
15:27:26
Info
file.csv
15:27:26
Info
Fri Sep 17 11:51:35 GMT+02:00 2021
15:27:27
Info
[[Name, Given Name, Additional Name, Family Name, Yomi Name, Given Name Yomi, Additional Name Yomi, Family Name Yomi, Name Prefix, Name Suffix, Initials, Nickname, Short Name, Maiden Name, Birthday, Gender, Location, Billing Information, Directory Server, Mileage, Occupation, Hobby, Sensitivity, Priority, Subject, Notes, Language, Photo, Group Membership, E-mail 1 - Type, E-mail 1 - Value, Phone 1 - Type, Phone 1 - Value, Address 1 - Type, Address 1 - Formatted, Address 1 - Street, Address 1 - City, Address 1 - PO Box, Address 1 - Region, Address 1 - Postal Code, Address 1 - Country, Address 1 - Extended Address, Organization 1 - Type, Organization 1 - Name, Organization 1 - Yomi Name, Organization 1 - Title, Organization 1 - Department, Organization 1 - Symbol, Organization 1 - Location, Organization 1 - Job Description, Website 1 - Type, Website 1 - Value], [Anna Musterfrau, Anna, , Musterfrau, , , , , , , , , , , , , , , , , , , , , , , , , * myContacts, * Home, anna#musterfrau.de, Mobile, +491234567890, , , , , , , , , , , , , , , , , , , ], [Hans Meise, Hans, , Meise, , , , , , , , , , , , , , , , , , , , , , , , , * myContacts, * Home, meinse#hans.de, , , , , , , , , , , , , , , , , , , , , ], [Hans Mustermann, Hans, , Mustermann, , , , , , , , , , , , , , , , , , , , , , , , , * myContacts, * , hans#mustermann.de, Main, +4912345 98765, , Nebenstrasse 122, , , , , , , , , , , , , , , , , ], [Musterhausen 12345, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [DE", Nebenstrasse 122, Musterhausen, , , 12345, DE, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ]
How do you run this script?
on https://script.google.com/home with "execude"
the script should run automated with a trigger
so that the contacts will add every day from the CSV file
a script to delete all conacts I found an this work.
But need to add the contacts from CSV file...
Contacts-Source is CSV File, automated import with apps script
every day by using a trigger
Plan is: CSV --> direct Google Contacts Import with Apps Script by using a trigger

Apps Script Copy sheet to another spreadsheet very large data

I have a very large sheet I need to copy from one spreadsheet into another and I noticed the routine has been failing, probably because the sheet is very big (8000 rows x 40 columns).
This is my old routine:
function doACopy() {
var sourceSS = SpreadsheetApp.openById('SOURCE SHEET');
var targetSS = SpreadsheetApp.openById('TARGET SHEET');
var sourceSheet = sourceSS.getSheetByName('Links Added');
var targetSheet = targetSS.getSheetByName('Links Added');
var sourceArray = sourceSheet.getDataRange().getValues();
targetSheet.clear();
var rows = sourceArray.length;
var columns = sourceArray[0].length;
targetSheet.getRange(1, 1, rows, columns).setValues(sourceArray);
}
I need something faster as I think it's surpassing the Apps script 6 minute timeout.
I tried using sheet.copyTo(Spreadsheet) but unfortunately it makes a new sheet in the target spreadsheet and formulas referring to to the previous copy are lost. I need a way to copy into the existing target sheet, not to create a new sheet.
EDIT: Here is the transcript of a successful run. You can see most of the time was used for getRange() which seems strange:
[18-04-16 04:24:58:810 PDT] Starting execution
[18-04-16 04:24:58:943 PDT] SpreadsheetApp.openById([1v2SHCynnH0iHvNdWQcBNgbgkMf-EaVzAzAqTbtFpjqw]) [0.126 seconds]
[18-04-16 04:24:59:036 PDT] SpreadsheetApp.openById([1dLs8FQeyPPKjIp-4RwQGTHlrYxaYA65rf0fbIBgyOhE]) [0.091 seconds]
[18-04-16 04:24:59:036 PDT] Spreadsheet.getSheetByName([Links Added]) [0 seconds]
[18-04-16 04:24:59:037 PDT] Spreadsheet.getSheetByName([Links Added]) [0 seconds]
[18-04-16 04:24:59:798 PDT] Sheet.getDataRange() [0.76 seconds]
[18-04-16 04:25:04:756 PDT] Range.getValues() [4.957 seconds]
[18-04-16 04:25:04:874 PDT] Sheet.clear() [0 seconds]
[18-04-16 04:25:04:874 PDT] Sheet.getRange([1, 1, 8131, 37]) [0 seconds]
[18-04-16 04:30:34:047 PDT] Range.setValues([[[Domain, Donor URL, Anchor text, Target URL, Date link added, Words in surrounding Text, Surrounding maximum text distance from link (number of words away, 0=anywhere), Date Surrounding text added, Link Status, Project, U, , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
[18-04-16 04:30:56:947 PDT] Execution succeeded [335.231 seconds total runtime]
Try sourceRange.copyTo(destinationRange)

MySQL - structure a query with different values that requires a lookup from the same table

This is my query:
SELECT f.pending
, f.title
, f.funeraltype
, f.firstname
, f.middlename
, f.lastname
, f.suffix
, f.displayage
, f.age
, f.displaycity
, f.city
, f.displaydate
, f.date
, f.aftersunset
, f.funeraldate
, f.displayfuneraldate
, f.ftime
, f.displayservicelocation
, l.location
, f.displaycemetery
, c.name
, f.displayobituary
, f.obituary
, f.displaycharity1
, ch.name
, f.charity1memo
, f.displaycharity2
, f.charity2
, f.charity2memo
, f.displaycharity3
, f.charity3
, f.charity3memo
, f.displaycharity4
, f.charity4
, f.charity4memo
, f.displaycharity5
, f.charity5
, f.charity5memo
, f.memorialbook
, f.displayshiva
, f.displaytime
, f.shivaendpart
, f.shivauntil
, f.shivaatresidence
, f.shivaname
, f.shivaaddress
, f.shivacity
, f.shivastate
, f.shivazip
, f.shivaphone
, f.shivacomment
, f.displayfamilymembers
, f.familymembers
, f.displayclergy
, f.clergy
, f.livevideo
, f.archivevideo
, f.video
, f.usemp4video
, f.mp4video
, f.custom_text
, f.charities_footnote
, f.charity1note
, f.charity2note
, f.charity3note
, f.charity4note
, f.charity5note
FROM funerals f
, locations l
, cemeteries c
, charities ch
WHERE f.servicelocation = l.locationid
AND f.cemetery = c.cemeteryID
AND f.charity1 = ch.CharityID
AND f.charity2 = ch.CharityID
AND f.charity3 = ch.CharityID
AND f.charity4 = ch.CharityID
AND f.charity5 = ch.CharityID
ch.name is what I'm looking to extract. f.charity1, f.charity2, f.charity3, f.charity4, & f.charity5 all contain different IDs that require a lookup in the 'charities' table. How would I structure this query to display each charity name?
SELECT f.pending
, l.location
, f.displaycemetery
, c.name
, f.displaycharity1
, ch.name
, f.charity1memo
, f.displaycharity2
, f.charity2
, f.charity2memo
, f.displaycharity3
, f.charity3
, f.charity3memo
, f.displaycharity4
, f.charity4
, f.charity4memo
, f.displaycharity5
, f.charity5
, f.charity5memo
, f.charity1note
, f.charity2note
, f.charity3note
, f.charity4note
, f.charity5note
FROM funerals f
JOIN locations l
ON l.locationid = f.servicelocation
JOIN cemeteries c
ON c.cemeteryID = f.cemetery
JOIN charities ch1
ON ch1.CharityID = f.charity1
JOIN charities ch2
ON ch2.CharityID = f.charity2
etc.
try this:
SELECT
f.pending
, f.title
, f.funeraltype
, f.firstname
, f.middlename
, f.lastname
, f.suffix
, f.displayage
, f.age
, f.displaycity
, f.city
, f.displaydate
, f.date
, f.aftersunset
, f.funeraldate
, f.displayfuneraldate
, f.ftime
, f.displayservicelocation
, l.location
, f.displaycemetery
, c.name
, f.displayobituary
, f.obituary
, f.displaycharity1
, ch1.name
, ch2.name
, ch3.name
, ch4.name
, ch5.name
, f.charity1memo
, f.displaycharity2
, f.charity2
, f.charity2memo
, f.displaycharity3
, f.charity3
, f.charity3memo
, f.displaycharity4
, f.charity4
, f.charity4memo
, f.displaycharity5
, f.charity5
, f.charity5memo
, f.memorialbook
, f.displayshiva
, f.displaytime
, f.shivaendpart
, f.shivauntil
, f.shivaatresidence
, f.shivaname
, f.shivaaddress
, f.shivacity
, f.shivastate
, f.shivazip
, f.shivaphone
, f.shivacomment
, f.displayfamilymembers
, f.familymembers
, f.displayclergy
, f.clergy
, f.livevideo
, f.archivevideo
, f.video
, f.usemp4video
, f.mp4video
, f.custom_text
, f.charities_footnote
, f.charity1note
, f.charity2note
, f.charity3note
, f.charity4note
, f.charity5note
FROM funerals f
INNER JOIN locations l on f.servicelocation = l.locationid
INNER JOIN cemeteries c ON f.cemetery = c.cemeteryID
INNER JOIN charities ch1 ON f.charity1 = ch1.CharityID
INNER JOIN charities ch2 ON f.charity2 = ch2.CharityID
INNER JOIN charities ch3 ON f.charity3 = ch3.CharityID
INNER JOIN charities ch4 ON f.charity4 = ch4.CharityID
INNER JOIN charities ch5 ON f.charity5 = ch5.CharityID

Syntax Error in INSERT INTO statement, no other details given

The SQL generated my code looks like this -
INSERT INTO [Item] (
Vendor_num
, item
, [Desc]
, Pack
, item_size
, unit_of_sale
, allowance
, points
, Promo
, WS_Cost
, WS_Unit_cost
, Retailer_Price
, Retail
, Cust_Use
, Show_Price
, GP
, Min
, Max
, Book_Number
, Del1_date
, Del2_date
, Del3_date
, Del4_date
, Del5_date
, Del6_date
, Del7_date
, Del8_date
, Del9_date
, Del10_date
, Del11_date
, Del12_date
, Del13_date
, Del14_date
, Del15_date
, warehouse
, Purchase_Group
, GPM
, Material_Number
, PM
) VALUES (
'11'
, '300681'
, 'item description'
, '60'
, 'BOX'
, 'BOX'
, '3'
, '20'
, 'Y'
, '0'
, null
, '0'
, null
, '03652'
, null
, null
, null
, null
, '832'
, '6/2/2014 12:00:00 AM'
, '6/30/2014 12:00:00 AM'
, '7/28/2014 12:00:00 AM'
, '8/18/2014 12:00:00 AM'
, null
, null
, null
, null
, null
, null
, null
, null
, null
, null
, null
, '1'
, null
, null
, null
, null
)
(forgive all those null values, they're frequently not null in these inserts, so the statement needs to be flexible enough when they're not)
I'm getting a generic error --
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement.
The statement works fine when copied directly into a new query in Access, but when firing through .NET and OLE DB, it fails miserably.
Any ideas?
Min and Max are reserved words in Access, and should be quoted if you use them as field names or you may encounter errors;
If a reserved word is already in use, you can avoid error messages by surrounding each occurrence of the word with brackets ([ ]). However, the best solution is to change the name to a nonreserved word.
In other words, used as field names, they should be quoted as [Min] and [Max].

SQL error for operand

I have used the same query to transfer from one database to another for ages, but suddenly I am getting the error
"Operand should contain 1 column(s)"
Here is my SQL:
INSERT INTO lightand_expressionengine.exp_channel_data (
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
)
SELECT (
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
)
FROM lightand_expressionengineold.exp_channel_data
Can anyone see what the issue is? I cant figure it out.
Remove the opening and closing brackets i.e. (...) from the SELECT. I.e. try the following SQL.
INSERT INTO lightand_expressionengine.exp_channel_data (
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
)
SELECT
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
FROM lightand_expressionengineold.exp_channel_data