2011-06-27 64 views
6

我有一個情況表,我有一個名爲氣體流量我要添加記錄的訪問表。當我嘗試運行我的插入查詢類似的表常見站,我得到以下錯誤:查詢有空格在其名稱中

"error hy000: syntax error, in query incomplete query clause"

代碼是:

using System; 
using System.Data.Odbc; 

class MainClass 
{ 
static void Main(string[] args) 
{ 
    string connectionString = "Dsn=Gas_meter"; 
    string sqlins = ""; 
    OdbcConnection conn = new OdbcConnection(connectionString); 

    OdbcCommand cmdnon = new OdbcCommand(sqlins, conn); 
    conn.Open(); 

    try 
    { 
     cmdnon.CommandText = "INSERT INTO 'Common station' (S1Flow, S2Flow, S3Flow, S4Flow) VALUES (9999,999, 999, 999)"; 
     //Once the above line works replace it with cmdnon.CommandText= "INSERT INTO Gas Flow Rates (S1Flow, S2Flow, S3Flow, S4Flow) VALUES (9999,999, 999, 999)" 
     int rowsAffected = cmdnon.ExecuteNonQuery(); 
     Console.WriteLine(rowsAffected); 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine(ex.ToString()); 
    } 
    finally 
    { 
     conn.Close(); 
    } 
} 
} 

如何克服這種錯誤?

回答

33

環繞隔開方括號項:

[Common station] 

然後就打誰設計的數據庫的傢伙。

+1

謝謝你,我絕對會,如果他沒有活亞利桑那州。我想,我會送他查普爾秀裏克詹姆斯小品,其中裏克詹姆斯告訴他什麼也五指說在臉上笑話的片段。 LMBO –

+0

我對使用關鍵字作爲列名的人有問題。相同的解決方案(即[] - 也許是巴掌?)。有理由我們不這樣做(可維護性是否意味着什麼?)。 –

+0

不是真的,它並不認爲不能從任Gas_Flow_Rates或GasFlowRates得到的任何重視。就我所知,這只是他創建桌子的方式。 –

3
cmdnon.CommandText = "INSERT INTO '[Common station]' (S1Flow, S2Flow, S3Flow, S4Flow) VALUES (9999,999, 999, 999)"; 
    //Once the above line works replace it with cmdnon.CommandText= "INSERT INTO Gas Flow Rates (S1Flow, S2Flow, S3Flow, S4Flow) VALUES (9999,999, 999, 999)" 
3

SELECT * FROM [My Crazy Table With Spaces and Other Chars!]

使用括號 「報價」 表和字段名稱。

1

遲到了,我知道,但剛剛解決了我自己的問題在這裏... 在2007年獲得使用播放ODBC連接到SQL數據庫。

表名是Employee_Appointment額外的細節自定義 語法選擇是「從[僱員]。[委任額外的細節自定義]選擇*」,康涅狄格州,ADOPENSTATIC,ADLOCKOPTIMISTIC

希望這樣可以節省如下 SQlRecordSet.Open別人玩幾個小時!

相關問題