我正在使用c#SqlCommand将版本号插入nvarchar(50)的revVersion字段中。对于像1.13或1.6这样的值,这没问题,但是对于值1.18.1.12,我得到了
System.Data.SqlClient.SqlException:“ .1附近的语法不正确。”
这是错误的命令:
"INSERT INTO Revision (revVersion,year,month,day,numLinesAdded,numLinesRemoved,moduleName) VALUES (1.18.1.12,2015,10,29,7,5,'bp-bn-bmfilter-600.m1,v')"
谢谢您的想法!
答案 0 :(得分:1)
您缺少单引号' '
(1.18.1.12
)和','
('bp-bn-bmfilter-600.m1,v'
):
INSERT INTO Revision (revVersion, year, month, day, numLinesAdded, numLinesRemoved, moduleName)
VALUES ('1.18.1.12', 2015, 10, 29, 7, 5, 'bp-bn-bmfilter-600.m1', 'v');
答案 1 :(得分:0)
您需要使用引号'1.18.1.12',因为其数据类型为nvarchar
INSERT INTO Revision (revVersion,year,month,day,numLinesAdded,numLinesRemoved,moduleName)
VALUES ('1.18.1.12',2015,10,29,7,5,'bp-bn-bmfilter-600.m1','v');
答案 2 :(得分:0)
1.13或1.6都是数字,但是1.18.1.12这不是数字,这就是为什么会出错
您必须像下面那样更改其字符串格式
INSERT INTO Revision (revVersion,year,month,day,numLinesAdded,numLinesRemoved,moduleName)
VALUES ('1.18.1.12',2015,10,29,7,5,'bp-bn-bmfilter-600.m1','v');
答案 3 :(得分:0)
缺少单引号:
INSERT INTO Revision (revVersion,year,month,day,numLinesAdded,numLinesRemoved,moduleName) VALUES ('1.18.1.12',2015,10,29,7,5,'bp-bn-bmfilter-600.m1,v')