查询名称中包含空格的表
我有一个情况,我有一个名为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(); } } }
我该如何克服这个错误?
用方括号围绕隔开的项目:
[Common station]
然后拍打设计数据库的人。
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)"
SELECT * FROM [My Crazy Table With Spaces and Other Chars!]
使用括号“引用”表和字段名称。
在我认识的派对上,但刚刚解决了我自己的问题…使用ODBC连接到SQL Db在Access 2007中播放。
表名是Employee_Appointment Extra Detail自定义语法选择如下SQlRecordSet.Open“Select * from [Employee]。[Appointment Extra Detail Custom]”,Conn,adOpenStatic,adLockOptimistic
希望这可以节省其他人几个小时的游戏时间!
上述就是C#学习教程:查询名称中包含空格的表分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1030018.html