查询名称中有空格的表

发布于 2024-11-17 13:10:40 字数 1060 浏览 6 评论 0原文

我有一种情况,我有一个名为 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();
    }
}
}

如何克服该错误?

I have a situation, I have a Access table named Gas Flow Rates that I want to add records. When I try to run my insert query for a similar table Common Station, I get the following error:

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

Code is:

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();
    }
}
}

How do I overcome that error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

手心的海 2024-11-24 13:10:40

用方括号将间隔开的项目括起来:

[Common station]

然后扇设计数据库的人一巴掌。

Surround the spaced out item with square brackets:

[Common station]

Then slap the guy who designed the database.

胡渣熟男 2024-11-24 13:10:40

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

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

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

Use brackets to "quote" table and field names.

枫以 2024-11-24 13:10:40
  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)"
  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)"
仅一夜美梦 2024-11-24 13:10:40

我知道参加聚会迟到了,但刚刚在这里解决了我自己的问题......
使用 ODBC 连接到 SQL 数据库在 Access 2007 中进行游戏。

表名称为 Employee_Appointment 额外详细信息自定义
选择的语法如下
SQlRecordSet.Open“从[员工]中选择*。[预约额外详细信息自定义]”,Conn,adOpenStatic,adLockOptimistic

希望这可以节省其他人几个小时的游戏时间!

Late to the party I know, but have just solved my own issue here...
Playing in access 2007 using ODBC connection to an SQL Db.

Table name is Employee_Appointment Extra Detail Custom
Syntax to select is as follows
SQlRecordSet.Open "Select * from [Employee].[Appointment Extra Detail Custom]", Conn, adOpenStatic, adLockOptimistic

Hope this saves someone else a few hours of playing!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文