[英]Invalid column name 'allocationStart'
无论出于何种原因,我在尝试执行查询时收到错误“无效的列名allocationStart
”。 这是在dateadd
函数内,并且列DOES存在于数据库中。 这是一个datetime
。
这是查询:
cmd.commandText = "Insert Into EmpPac
(catalogIdent, empPacIdent, empIdent, allocation,
quantityLimit, quantityIssued, quantityShipped,
allocationMonths, sizeChartIdent, sizeNotes, nextUpdate)
values ( '" & catalogIdent & "', '" & intvalue_EmpPak
& "', '" & empIdent & "',"&jobQuantityLimit&",'"
&jobQuantityLimit&"', '0', '0',"&
allocationMonths&", '"& sizeChartident &
"', '', DATEADD(month, "&allocationMonths&
", allocationStart))"
cmd.execute
您没有指定table allocationstart
所在的表。
您需要使您的INSERT
源成为源表中的SELECT
,而不是使用VALUES
关键字,因为它需要显式值列表。
例如:
INSERT INTO MyTargetTable
SELECT <stuff>, DATEADD(month, XXX, allocationstart)
FROM MySourceDataTable
我会说实话 - 我没有100%关注你的问题,但我想我明白你要做的事情。
原始错误源自DATEADD命令。
DATEADD的第三个参数是要操作的日期时间值。
我猜你的“allocationStart”列在DB中自动设置当前日期时间,并将该列传递给DATEADD函数来操作它并将返回的值插入“nextUpdate”列。 如果这是您要执行的操作,则不会设置auto datetime列(能够返回日期/时间等),直到提交行为止,因此您无法在INSERT语句内使用函数内的auto = generated列。
我还强烈建议你看看参数,它更安全,更好的做法。
如果您在“nextUpdate”列的月份编号之后,可以使用DateTime.Now.Month并将其附加到SQL字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.