查询名称中包含空格的表

LaD*_*ley 8 c# ms-access-2007 tablename

我有一个情况,我有一个名为Gas Flow Rates的Access表,我想添加记录.当我尝试为类似的表Common Station运行插入查询时,出现以下错误:

"错误hy000:语法错误,在查询不完整查询子句中"

代码是:

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();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

我该如何克服这个错误?

Gre*_*mer 41

用方括号围绕间隔开的项目:

[Common station]
Run Code Online (Sandbox Code Playgroud)

然后拍打设计数据库的人.

  • 谢谢,如果他不住亚利桑那州,我绝对会这样做.我想我会给他发一张Chappelle节目里克詹姆斯小品的片段,里克詹姆斯告诉他这五个手指对于笑话说了什么.LMBO (2认同)

Mik*_*ron 5

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

使用方括号“引用”表和字段名称。