我确定我在做一些愚蠢的事情,但是我似乎可以弄清楚这个插入查询的问题。我对SQL Server有一定的经验,但是不幸的是,我不得不为此项目使用Access(这是我的新手)。在这一点上,我已经尝试过手动插入Access(有效),然后将确切的查询复制到Visual Studio中,但仍然出现插入语法错误。我可以在同一测试程序中插入其他表,但无法使该查询正常工作。
我要插入的表设置为:
ID - Int Primary Key
time_series_id Int
open decimal
high decimal
low decimal
close decimal
volume int
observation_date Date/Time
我尝试的手动查询是:
queryString = "INSERT INTO daily_prices (time_series_id, open, high, low, close, volume, observation_date) VALUES(13, 3036.75, 3045.72, 3023.27, 3027.52, 4894428992, '2013-09-24')";
command = new OleDbCommand(queryString, conn);
command.ExecuteNonQuery();
该查询最初还通过以下方式制定:
queryString = String.Format(@"INSERT INTO daily_prices (time_series_id, open, high, low, close, volume, observation_date) VALUES ({0}, {1} ,{2} ,{3} ,{4} ,{5} ,'{6}')", newId, open, high, low, close, volume, date);
任何帮助将不胜感激。我敢肯定这是一个愚蠢的错误,但是我有点茫然,因为我能够在Access中执行查询,然后同一查询在C#中失败。
单词OPEN和CLOSE是Jet-SQL(Jet 4.0)的保留关键字。在方括号周围使用方括号(或在可能的情况下更改列名称)
queryString = "INSERT INTO daily_prices (time_series_id, [open], high, low, " +
"[close], volume, observation_date) VALUES " +
"(13, 3036.75, 3045.72, 3023.27, 3027.52, 4894428992, '2013-09-24')";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句