简体   繁体   中英

My insert command is failing from C#

I have large data table and I am using an insert command to put the data into an mdb access table. I am looping through the array of columns which I got from the data table to produce the names and values for the insert command. It keeps saying I have a syntax error and I have no clue why because the syntax is fine.

INSERT INTO tbl01_General (PIN, PROJ_CAT, MFT, MAJFUND, OTHFUND, WORKTYPE, WORK_LABEL, FUND_DATE, ORIG_DATE, LET_DATE, MUNIC, DISTRICT, ROUTE, FROM, TO, MP1, MP2, MILES, FAS, DESCRIPTN, RESPAGENCY, CURR_PHASE, DEPARTMENT, PROJMGR, STATUS, CONT_COST, COSTBASIS, COSTDATE, BASECOST, BASEDATE, PROJ_COST, FED_FLAG, TAG_FLAG, REV_FLAG, COM_FLAG, TIP_FLAG, CON_FLAG, CON_S, CON_P, CON_D, CON_R, CON_C, CON_I, CON_O, DEPT_S, DEPT_P, DEPT_D, DEPT_R, DEPT_C, DEPT_I, DEPT_M, DEPT_L, PGM_DATE, PGM6Y_DATE, LASTUPDATE, NEEDS_TIP_INFO, SEQ_NUMBER, SELECTED, MFT_Closed_Section, SSMA_TimeStamp)   
VALUES ('B-00099', 'P', '08-00118-09-BR', 'Null', 'Null', 'Drainage', '2', '01/01/2013', '01/01/2013', '04/16/2013', 'North Barrington', 'CB-17', 'Miller Rd', '@ 0.3 mi east of', 'IL Rte 59', '0', '0', '0.3', 'Null', 'Construct 3-span Bridge and Embanked Road\r\nin order to alleviate road flooding\r\n\r\n\r\n', 'LCDOT', 'Null', 'Design', 'Construction', '', '150.0000', 'Per Al Giertych', '02/17/2011', '2600.0000', '02/17/2011', '3735.3000', 'False', 'False', 'False', 'True', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'Null', 'Null', 'Null', 'Null', 'Null', 'Null', 'Null', 'Null', '01/11/2001', '05/11/2001', '02/14/2014', 'False', 'Null', 'False', 'False', 'System.Byte[]')"

Syntax error with insert command

Unfortunately this also didn't work: @David

INSERT INTO [tbl01_General] (PIN, PROJ_CAT, MFT, MAJFUND, OTHFUND, WORKTYPE, WORK_LABEL, FUND_DATE, ORIG_DATE, LET_DATE, MUNIC, DISTRICT, ROUTE, FROM, TO, MP1, MP2, MILES, FAS, DESCRIPTN, RESPAGENCY, CURR_PHASE, DEPARTMENT, PROJMGR, STATUS, CONT_COST, COSTBASIS, COSTDATE, BASECOST, BASEDATE, PROJ_COST, FED_FLAG, TAG_FLAG, REV_FLAG, COM_FLAG, TIP_FLAG, CON_FLAG, CON_S, CON_P, CON_D, CON_R, CON_C, CON_I, CON_O, DEPT_S, DEPT_P, DEPT_D, DEPT_R, DEPT_C, DEPT_I, DEPT_M, DEPT_L, PGM_DATE, PGM6Y_DATE, LASTUPDATE, NEEDS_TIP_INFO, SEQ_NUMBER, SELECTED, MFT_Closed_Section, SSMA_TimeStamp)   
VALUES ([B-00099], [P], [08-00118-09-BR], [Null], [Null], [Drainage], [2], [01/01/2013], [01/01/2013], [04/16/2013], [North Barrington], [CB-17], [Miller Rd], [@ 0.3 mi east of], [IL Rte 59], [0], [0], [0.3], [Null], [Construct 3-span Bridge and Embanked Road\r\nin order to alleviate road flooding\r\n\r\n\r\n], [LCDOT], [Null], [Design], [Construction], [], [150.0000], [Per Al Giertych], [02/17/2011], [2600.0000], [02/17/2011], [3735.3000], [False], [False], [False], [True], [False], [False], [False], [False], [False], [False], [False], [False], [False], [Null], [Null], [Null], [Null], [Null], [Null], [Null], [Null], [01/11/2001], [05/11/2001], [02/14/2014], [False], [Null], [False], [False], [System.Byte[]])

At least one of your columns names is a reserved word . In this case, at least the column FROM . This is confusing the query parser.

In order to specify that you are referring to an object by that name and not using the FROM keyword, enclose the object names in square brackets:

INSERT INTO [tbl01_General] ([PIN], [PROJ_CAT], [MFT] ...

You don't technically need to enclose all of them , just the ones which would confuse the parser. But you say that you're dynamically building the column names so that code would likely enclose all of them.

除了将许多字段名称括起来之外,您还需要正确格式化日期表达式,并且不能引用小数:

..., 'Per Al Giertych', #02/17/2011#, 2600.0000, ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM