我的插入命令失败了C#

时间:2015-06-26 17:58:47

标签: c# sql ms-access

我有大数据表,我使用insert命令将数据放入mdb访问表。我循环遍历从数据表中获取的列数组,以生成insert命令的名称和值。它一直说我有语法错误,我不知道为什么因为语法很好。

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[]')"

使用insert命令的语法错误

不幸的是,这也没有用:@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[]])

2 个答案:

答案 0 :(得分:0)

至少有一个列名是reserved word。在这种情况下,至少列FROM。这使查询解析器感到困惑。

为了指定您使用该名称引用对象而不使用FROM关键字,请将对象名称括在方括号中:

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

您在技术上不需要将所有这些包围起来,只是那些会使解析器混淆的内容。但是你说你正在动态构建列名,以便代码可能包含所有这些名称。

答案 1 :(得分:0)

除了包含许多字段名称之外,还需要正确格式化日期表达式,并且不得引用小数:

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