查询名称中有空格的表
我有一种情况,我有一个名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
用方括号将间隔开的项目括起来:
然后扇设计数据库的人一巴掌。
Surround the spaced out item with square brackets:
Then slap the guy who designed the database.
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.
我知道参加聚会迟到了,但刚刚在这里解决了我自己的问题......
使用 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!