[英]MS Access SQL Insert Query
我確定我在做一些愚蠢的事情,但是我似乎可以弄清楚這個插入查詢的問題。 我對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')";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.